feat: park page operating window check; always show ride total
All checks were successful
Build and Deploy / Build & Push (push) Successful in 5m54s
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:
25
app/page.tsx
25
app/page.tsx
@@ -5,7 +5,7 @@ import { Legend } from "@/components/Legend";
|
||||
import { EmptyState } from "@/components/EmptyState";
|
||||
import { PARKS, groupByRegion } from "@/lib/parks";
|
||||
import { openDb, getDateRange } from "@/lib/db";
|
||||
import { getTodayLocal } from "@/lib/env";
|
||||
import { getTodayLocal, isWithinOperatingWindow } from "@/lib/env";
|
||||
import { fetchLiveRides } from "@/lib/scrapers/queuetimes";
|
||||
import { QUEUE_TIMES_IDS } from "@/lib/queue-times-map";
|
||||
|
||||
@@ -13,29 +13,6 @@ interface PageProps {
|
||||
searchParams: Promise<{ week?: 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".
|
||||
*/
|
||||
function isWithinOperatingWindow(hoursLabel: string): boolean {
|
||||
const m = hoursLabel.match(
|
||||
/^(\d+)(?::(\d+))?(am|pm)\s*[–-]\s*(\d+)(?::(\d+))?(am|pm)$/i
|
||||
);
|
||||
if (!m) return true; // unparseable — show anyway
|
||||
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;
|
||||
}
|
||||
|
||||
function getWeekStart(param: string | undefined): string {
|
||||
if (param && /^\d{4}-\d{2}-\d{2}$/.test(param)) {
|
||||
const d = new Date(param + "T00:00:00");
|
||||
|
||||
Reference in New Issue
Block a user