Merge pull request 'timezone' (#15) from claude/suspicious-wilson into master
Reviewed-on: #15
This commit was merged in pull request #15.
This commit is contained in:
@@ -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: {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user