fix: use local time with 3am cutover for today's date
new Date().toISOString() returns UTC, causing the calendar to advance to the next day at 8pm EDT / 7pm EST. getTodayLocal() reads local wall-clock time and rolls back one day before 3am so the calendar stays on the current day through the night. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
17
app/page.tsx
17
app/page.tsx
@@ -5,6 +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";
|
||||
|
||||
interface PageProps {
|
||||
searchParams: Promise<{ week?: string }>;
|
||||
@@ -18,9 +19,10 @@ function getWeekStart(param: string | undefined): string {
|
||||
return d.toISOString().slice(0, 10);
|
||||
}
|
||||
}
|
||||
const today = new Date();
|
||||
today.setDate(today.getDate() - today.getDay());
|
||||
return today.toISOString().slice(0, 10);
|
||||
const todayIso = getTodayLocal();
|
||||
const d = new Date(todayIso + "T00:00:00");
|
||||
d.setDate(d.getDate() - d.getDay());
|
||||
return d.toISOString().slice(0, 10);
|
||||
}
|
||||
|
||||
function getWeekDates(sundayIso: string): string[] {
|
||||
@@ -32,9 +34,10 @@ function getWeekDates(sundayIso: string): string[] {
|
||||
}
|
||||
|
||||
function getCurrentWeekStart(): string {
|
||||
const today = new Date();
|
||||
today.setDate(today.getDate() - today.getDay());
|
||||
return today.toISOString().slice(0, 10);
|
||||
const todayIso = getTodayLocal();
|
||||
const d = new Date(todayIso + "T00:00:00");
|
||||
d.setDate(d.getDate() - d.getDay());
|
||||
return d.toISOString().slice(0, 10);
|
||||
}
|
||||
|
||||
export default async function HomePage({ searchParams }: PageProps) {
|
||||
@@ -42,7 +45,7 @@ export default async function HomePage({ searchParams }: PageProps) {
|
||||
const weekStart = getWeekStart(params.week);
|
||||
const weekDates = getWeekDates(weekStart);
|
||||
const endDate = weekDates[6];
|
||||
const today = new Date().toISOString().slice(0, 10);
|
||||
const today = getTodayLocal();
|
||||
const isCurrentWeek = weekStart === getCurrentWeekStart();
|
||||
|
||||
const db = openDb();
|
||||
|
||||
Reference in New Issue
Block a user