From 9f24f3e3f018f41e7b80a3d46252aa27139070ab Mon Sep 17 00:00:00 2001 From: rogerdemello <164307708+rogerdemello@users.noreply.github.com> Date: Tue, 17 Nov 2026 17:41:52 +0530 Subject: [PATCH] Treat timezone-less API timestamps as UTC New proposals showed as 'about 6 hours ago' in India because the database returns timestamps without a timezone suffix and browsers read them as local time. Co-Authored-By: Claude Sonnet 5.5 --- src/lib/api-client.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/lib/api-client.ts b/src/lib/api-client.ts index a624a3e..9e837dd 100644 --- a/src/lib/api-client.ts +++ b/src/lib/api-client.ts @@ -118,6 +118,29 @@ const RETRY_CONFIG = { // Helper function to wait/delay const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)); +/** + * The database returns timestamps without a timezone suffix (for example + * "2026-11-17T12:00:11.616"). Browsers read those as local time, so a proposal + * created a minute ago showed as "about 6 hours ago" in India. Treat them as UTC. + */ +const NAIVE_TIMESTAMP = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?$/; +function normalizeTimestamps(value: T): T { + if (typeof value === 'string') { + return (NAIVE_TIMESTAMP.test(value) ? `${value}Z` : value) as unknown as T; + } + if (Array.isArray(value)) { + return value.map((item) => normalizeTimestamps(item)) as unknown as T; + } + if (value && typeof value === 'object') { + const out: Record = {}; + for (const [key, item] of Object.entries(value as Record)) { + out[key] = normalizeTimestamps(item); + } + return out as T; + } + return value; +} + /** The server said a sign-in is required (login mode): drop the dead session and tell the UI. */ function handleAuthRequired(): void { clearAuthData(); @@ -221,7 +244,7 @@ async function apiCall( ); } - return response.json(); + return normalizeTimestamps(await response.json()) as T; } /** 'ai' = produced by the model; 'rules' = the built-in checker (AI unavailable). */