Fix date handling in logs API
This commit is contained in:
parent
36becd3dc0
commit
afb1555389
1 changed files with 4 additions and 4 deletions
|
|
@ -20,7 +20,7 @@ export async function POST(request: Request) {
|
||||||
return NextResponse.json({ error: "Missing required fields" }, { status: 400 });
|
return NextResponse.json({ error: "Missing required fields" }, { status: 400 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const now = new Date();
|
const now = new Date().toISOString();
|
||||||
|
|
||||||
if (type === "feed") {
|
if (type === "feed") {
|
||||||
await sql.unsafe(
|
await sql.unsafe(
|
||||||
|
|
@ -33,10 +33,10 @@ export async function POST(request: Request) {
|
||||||
[childId, subType, notes || null, now]
|
[childId, subType, notes || null, now]
|
||||||
);
|
);
|
||||||
} else if (type === "sleep") {
|
} else if (type === "sleep") {
|
||||||
const startTime = startedAt ? new Date(startedAt) : now;
|
const startTime = startedAt || now;
|
||||||
const endTime = endedAt ? new Date(endedAt) : null;
|
const endTime = endedAt || null;
|
||||||
const durationMinutes = endTime
|
const durationMinutes = endTime
|
||||||
? Math.round((endTime.getTime() - startTime.getTime()) / 60000)
|
? Math.round((new Date(endTime).getTime() - new Date(startTime).getTime()) / 60000)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
await sql.unsafe(
|
await sql.unsafe(
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue