fix: use park timezone for operating window check; show tz in hours
All checks were successful
Build and Deploy / Build & Push (push) Successful in 4m22s
All checks were successful
Build and Deploy / Build & Push (push) Successful in 4m22s
- isWithinOperatingWindow now accepts an IANA timezone and reads the current time in the park's local timezone via Intl.DateTimeFormat, fixing false positives when the server runs in UTC but parks store hours in local time (e.g. Pacific parks showing open at 6:50 AM EDT) - Remove the 1-hour pre-open buffer so parks are not marked open before their doors actually open; retain the 1-hour post-close grace period - Add getTimezoneAbbr() helper to derive the short tz label (EDT, PDT…) - All hours labels now display with the local timezone abbreviation (e.g. "10am – 6pm PDT") in WeekCalendar, ParkCard, and ParkMonthCalendar Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
39
lib/env.ts
39
lib/env.ts
@@ -35,11 +35,26 @@ export function getTodayLocal(): string {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true when the current local time is within 1 hour before open
|
||||
* or 1 hour after close, based on a hoursLabel like "10am – 6pm".
|
||||
* Falls back to true when the label can't be parsed.
|
||||
* Returns the short timezone abbreviation for a given IANA timezone,
|
||||
* e.g. "America/Los_Angeles" → "PDT" or "PST".
|
||||
*/
|
||||
export function isWithinOperatingWindow(hoursLabel: string): boolean {
|
||||
export function getTimezoneAbbr(timezone: string): string {
|
||||
const parts = new Intl.DateTimeFormat("en-US", {
|
||||
timeZone: timezone,
|
||||
timeZoneName: "short",
|
||||
}).formatToParts(new Date());
|
||||
return parts.find((p) => p.type === "timeZoneName")?.value ?? "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true when the current time in the park's timezone is within
|
||||
* the operating window (open time through 1 hour after close), based on
|
||||
* a hoursLabel like "10am – 6pm". Falls back to true when unparseable.
|
||||
*
|
||||
* Uses the park's IANA timezone so a Pacific park's "10am" is correctly
|
||||
* compared to Pacific time regardless of where the server is running.
|
||||
*/
|
||||
export function isWithinOperatingWindow(hoursLabel: string, timezone: string): boolean {
|
||||
const m = hoursLabel.match(
|
||||
/^(\d+)(?::(\d+))?(am|pm)\s*[–-]\s*(\d+)(?::(\d+))?(am|pm)$/i
|
||||
);
|
||||
@@ -53,7 +68,17 @@ export function isWithinOperatingWindow(hoursLabel: string): boolean {
|
||||
};
|
||||
const openMin = toMinutes(m[1], m[2], m[3]);
|
||||
const closeMin = toMinutes(m[4], m[5], m[6]);
|
||||
const now = new Date();
|
||||
const nowMin = now.getHours() * 60 + now.getMinutes();
|
||||
return nowMin >= openMin - 60 && nowMin <= closeMin + 60;
|
||||
|
||||
// Get the current time in the park's local timezone.
|
||||
const parts = new Intl.DateTimeFormat("en-US", {
|
||||
timeZone: timezone,
|
||||
hour: "numeric",
|
||||
minute: "2-digit",
|
||||
hour12: false,
|
||||
}).formatToParts(new Date());
|
||||
const h = parseInt(parts.find((p) => p.type === "hour")?.value ?? "0", 10);
|
||||
const min = parseInt(parts.find((p) => p.type === "minute")?.value ?? "0", 10);
|
||||
const nowMin = (h % 24) * 60 + min;
|
||||
|
||||
return nowMin >= openMin && nowMin <= closeMin + 60;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user