diff --git a/src/app/api/reports/route.ts b/src/app/api/reports/route.ts index fed0059..0bd9818 100644 --- a/src/app/api/reports/route.ts +++ b/src/app/api/reports/route.ts @@ -37,9 +37,12 @@ export async function POST(req: Request) { const body = await req.json(); const { managerName, date } = body; - // Check if a report already exists for this date and user - const reportDate = date ? new Date(date) : new Date(); - reportDate.setHours(0, 0, 0, 0); + // Check if a report already exists for this date and user. + // Client always sends a YYYY-MM-DD date string in Central US time; + // we store it as UTC midnight so the date string is stable across timezones. + const reportDate = date + ? new Date(`${date}T00:00:00.000Z`) + : new Date(new Date().toLocaleDateString('en-CA', { timeZone: 'America/Chicago' }) + 'T00:00:00.000Z'); let report = await prisma.report.findFirst({ where: { diff --git a/src/components/ReportForm.tsx b/src/components/ReportForm.tsx index 4106715..ba651b0 100644 --- a/src/components/ReportForm.tsx +++ b/src/components/ReportForm.tsx @@ -23,11 +23,15 @@ export default function ReportForm() { } }, [status]); + // Returns today's date as YYYY-MM-DD in Central US time + const getCentralToday = () => + new Date().toLocaleDateString('en-CA', { timeZone: 'America/Chicago' }); + const fetchReport = async () => { try { const res = await fetch("/api/reports"); const data = await res.json(); - const today = new Date().toISOString().split('T')[0]; + const today = getCentralToday(); const todayReport = data.find((r: any) => r.date.split('T')[0] === today); if (todayReport) { @@ -49,7 +53,7 @@ export default function ReportForm() { const res = await fetch("/api/reports", { method: "POST", headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ managerName }), + body: JSON.stringify({ managerName, date: getCentralToday() }), }); const data = await res.json(); setReport(data);