mirror of
https://github.com/Sea-Haven-Industries/meal-order-manager.git
synced 2026-09-30 08:53:13 +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;
|
||||
|
||||
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) {{
|
||||
if (data && data.reopen_at) {{
|
||||
reopenAtMs = data.reopen_at * 1000;
|
||||
|
|
@ -578,17 +602,15 @@ function updateCountdown() {{
|
|||
if (reopenAtMs) {{
|
||||
target = new Date(reopenAtMs);
|
||||
}} else {{
|
||||
const etStr = now.toLocaleString('en-US', {{ timeZone: 'America/New_York', hour12: false }});
|
||||
const etDate = new Date(etStr);
|
||||
const day = etDate.getDay();
|
||||
const hour = etDate.getHours();
|
||||
const etNow = getEasternParts(now);
|
||||
const day = new Date(Date.UTC(etNow.year, etNow.month - 1, etNow.day)).getUTCDay();
|
||||
const hour = etNow.hour;
|
||||
|
||||
let daysUntil = (1 - day + 7) % 7;
|
||||
if (daysUntil === 0 && hour >= 8) daysUntil = 7;
|
||||
|
||||
target = new Date(etDate);
|
||||
target.setDate(target.getDate() + daysUntil);
|
||||
target.setHours(8, 0, 0, 0);
|
||||
const targetEtMs = Date.UTC(etNow.year, etNow.month - 1, etNow.day + daysUntil, 8, 0, 0);
|
||||
target = new Date(targetEtMs - getEasternOffsetMs(new Date(targetEtMs)));
|
||||
}}
|
||||
|
||||
let diff = Math.max(0, Math.floor((target - now) / 1000));
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue