feat: park page operating window check; always show ride total
All checks were successful
Build and Deploy / Build & Push (push) Successful in 5m54s

- Extract isWithinOperatingWindow() to lib/env.ts (shared)
- Park detail page: always fetch Queue-Times, but force all rides
  closed when outside the ±1h operating window
- LiveRidePanel: always show closed ride count badge (not just when
  some rides are also open); label reads "X rides total" when none
  are open vs "X closed / down" when some are

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-04 20:43:33 -04:00
parent 8e969165b4
commit fbf4337a83
4 changed files with 44 additions and 29 deletions

View File

@@ -33,3 +33,27 @@ export function getTodayLocal(): string {
const d = String(now.getDate()).padStart(2, "0");
return `${y}-${m}-${d}`;
}
/**
* 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.
*/
export function isWithinOperatingWindow(hoursLabel: string): boolean {
const m = hoursLabel.match(
/^(\d+)(?::(\d+))?(am|pm)\s*[-]\s*(\d+)(?::(\d+))?(am|pm)$/i
);
if (!m) return true;
const toMinutes = (h: string, min: string | undefined, period: string) => {
let hours = parseInt(h, 10);
const minutes = min ? parseInt(min, 10) : 0;
if (period.toLowerCase() === "pm" && hours !== 12) hours += 12;
if (period.toLowerCase() === "am" && hours === 12) hours = 0;
return hours * 60 + minutes;
};
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;
}