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 body = await req.json();
|
||||||
const { managerName, date } = body;
|
const { managerName, date } = body;
|
||||||
|
|
||||||
// Check if a report already exists for this date and user
|
// Check if a report already exists for this date and user.
|
||||||
const reportDate = date ? new Date(date) : new Date();
|
// Client always sends a YYYY-MM-DD date string in Central US time;
|
||||||
reportDate.setHours(0, 0, 0, 0);
|
// 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({
|
let report = await prisma.report.findFirst({
|
||||||
where: {
|
where: {
|
||||||
|
|||||||
@@ -23,11 +23,15 @@ export default function ReportForm() {
|
|||||||
}
|
}
|
||||||
}, [status]);
|
}, [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 () => {
|
const fetchReport = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch("/api/reports");
|
const res = await fetch("/api/reports");
|
||||||
const data = await res.json();
|
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);
|
const todayReport = data.find((r: any) => r.date.split('T')[0] === today);
|
||||||
|
|
||||||
if (todayReport) {
|
if (todayReport) {
|
||||||
@@ -49,7 +53,7 @@ export default function ReportForm() {
|
|||||||
const res = await fetch("/api/reports", {
|
const res = await fetch("/api/reports", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({ managerName }),
|
body: JSON.stringify({ managerName, date: getCentralToday() }),
|
||||||
});
|
});
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
setReport(data);
|
setReport(data);
|
||||||
|
|||||||
Reference in New Issue
Block a user