mirror of
https://github.com/Sea-Haven-Industries/meal-order-manager.git
synced 2026-10-06 08:51:58 +00:00
Fix Eastern fallback countdown
This commit is contained in:
parent
26e1f5bbb4
commit
caa0504840
1 changed files with 29 additions and 7 deletions
|
|
@ -563,6 +563,30 @@ async function checkFormStatus() {{
|
||||||
|
|
||||||
let reopenAtMs = null;
|
let reopenAtMs = null;
|
||||||
|
|
||||||
|
const easternFormatter = new Intl.DateTimeFormat('en-US', {{
|
||||||
|
timeZone: 'America/New_York',
|
||||||
|
year: 'numeric',
|
||||||
|
month: '2-digit',
|
||||||
|
day: '2-digit',
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
second: '2-digit',
|
||||||
|
hourCycle: 'h23',
|
||||||
|
}});
|
||||||
|
|
||||||
|
function getEasternParts(date) {{
|
||||||
|
const values = {{}};
|
||||||
|
easternFormatter.formatToParts(date).forEach(part => {{
|
||||||
|
if (part.type !== 'literal') values[part.type] = Number(part.value);
|
||||||
|
}});
|
||||||
|
return values;
|
||||||
|
}}
|
||||||
|
|
||||||
|
function getEasternOffsetMs(date) {{
|
||||||
|
const parts = getEasternParts(date);
|
||||||
|
return Date.UTC(parts.year, parts.month - 1, parts.day, parts.hour, parts.minute, parts.second) - date.getTime();
|
||||||
|
}}
|
||||||
|
|
||||||
function startCountdown(data) {{
|
function startCountdown(data) {{
|
||||||
if (data && data.reopen_at) {{
|
if (data && data.reopen_at) {{
|
||||||
reopenAtMs = data.reopen_at * 1000;
|
reopenAtMs = data.reopen_at * 1000;
|
||||||
|
|
@ -578,17 +602,15 @@ function updateCountdown() {{
|
||||||
if (reopenAtMs) {{
|
if (reopenAtMs) {{
|
||||||
target = new Date(reopenAtMs);
|
target = new Date(reopenAtMs);
|
||||||
}} else {{
|
}} else {{
|
||||||
const etStr = now.toLocaleString('en-US', {{ timeZone: 'America/New_York', hour12: false }});
|
const etNow = getEasternParts(now);
|
||||||
const etDate = new Date(etStr);
|
const day = new Date(Date.UTC(etNow.year, etNow.month - 1, etNow.day)).getUTCDay();
|
||||||
const day = etDate.getDay();
|
const hour = etNow.hour;
|
||||||
const hour = etDate.getHours();
|
|
||||||
|
|
||||||
let daysUntil = (1 - day + 7) % 7;
|
let daysUntil = (1 - day + 7) % 7;
|
||||||
if (daysUntil === 0 && hour >= 8) daysUntil = 7;
|
if (daysUntil === 0 && hour >= 8) daysUntil = 7;
|
||||||
|
|
||||||
target = new Date(etDate);
|
const targetEtMs = Date.UTC(etNow.year, etNow.month - 1, etNow.day + daysUntil, 8, 0, 0);
|
||||||
target.setDate(target.getDate() + daysUntil);
|
target = new Date(targetEtMs - getEasternOffsetMs(new Date(targetEtMs)));
|
||||||
target.setHours(8, 0, 0, 0);
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
let diff = Math.max(0, Math.floor((target - now) / 1000));
|
let diff = Math.max(0, Math.floor((target - now) / 1000));
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue