From afb155538959cce809ec06caf3a572215f803146 Mon Sep 17 00:00:00 2001 From: Mannu Date: Sun, 10 May 2026 05:30:57 +0530 Subject: [PATCH] Fix date handling in logs API --- src/app/api/logs/route.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/api/logs/route.ts b/src/app/api/logs/route.ts index 0b1b61e..ea81d5d 100644 --- a/src/app/api/logs/route.ts +++ b/src/app/api/logs/route.ts @@ -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(