Fix date handling in logs API

This commit is contained in:
Manohar Gupta 2026-05-10 05:30:57 +05:30
parent 36becd3dc0
commit afb1555389

View file

@ -20,7 +20,7 @@ export async function POST(request: Request) {
return NextResponse.json({ error: "Missing required fields" }, { status: 400 });
}
const now = new Date();
const now = new Date().toISOString();
if (type === "feed") {
await sql.unsafe(
@ -33,10 +33,10 @@ export async function POST(request: Request) {
[childId, subType, notes || null, now]
);
} else if (type === "sleep") {
const startTime = startedAt ? new Date(startedAt) : now;
const endTime = endedAt ? new Date(endedAt) : null;
const startTime = startedAt || now;
const endTime = endedAt || null;
const durationMinutes = endTime
? Math.round((endTime.getTime() - startTime.getTime()) / 60000)
? Math.round((new Date(endTime).getTime() - new Date(startTime).getTime()) / 60000)
: null;
await sql.unsafe(