From 3a114cccd08d07e975bca9bd66ea568c6be27105 Mon Sep 17 00:00:00 2001 From: Marko Djordjevic Date: Tue, 17 Feb 2026 19:46:24 +0100 Subject: [PATCH] fix: convert Unix epoch seconds to Date before inserting annotation timestamp --- src/app/api/annotations/route.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/app/api/annotations/route.ts b/src/app/api/annotations/route.ts index 41d8ef1..7848706 100644 --- a/src/app/api/annotations/route.ts +++ b/src/app/api/annotations/route.ts @@ -60,18 +60,27 @@ export async function POST(request: NextRequest) { ); } + // timestamp from client is Unix epoch seconds; convert to Date for Postgres + const timestampDate = typeof timestamp === 'number' + ? new Date(timestamp * 1000) + : new Date(timestamp); + const result = await db .insert(annotations) .values({ chart_id, - timestamp, + timestamp: timestampDate, label_type, geometry: geometry || null, color: color || '#3b82f6', }) .returning(); - return NextResponse.json(result[0], { status: 201 }); + const row = result[0]; + return NextResponse.json({ + ...row, + timestamp: row.timestamp instanceof Date ? Math.floor(row.timestamp.getTime() / 1000) : row.timestamp, + }, { status: 201 }); } catch (error: any) { return NextResponse.json( { error: error.message || 'Failed to create annotation' },