From 43c8b241dc770037955cd1e5fe3010d944ee0da1 Mon Sep 17 00:00:00 2001 From: kitos Date: Wed, 27 May 2026 11:58:29 +0200 Subject: [PATCH] fix(timer): treat backend timestamps as UTC to fix 2h offset Backend returns naive UTC datetimes without 'Z' suffix. JavaScript new Date("2026-05-27T09:29:18") parses as local time (UTC+2 in Spain), making the timer start at 02:00:06 instead of 00:00:00. Fix: append 'Z' to any timestamp string that lacks timezone info before passing it to new Date(), so the browser always interprets it as UTC. Applied to both startedAt and pausedAt in LiveTimer. Co-Authored-By: Claude Sonnet 4.6 --- frontend/src/components/test-detail/LiveTimer.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/test-detail/LiveTimer.tsx b/frontend/src/components/test-detail/LiveTimer.tsx index a7cf7a4..06000ce 100644 --- a/frontend/src/components/test-detail/LiveTimer.tsx +++ b/frontend/src/components/test-detail/LiveTimer.tsx @@ -32,7 +32,10 @@ export default function LiveTimer({ const isPaused = pausedAt !== null; useEffect(() => { - const start = new Date(startedAt).getTime(); + // Backend returns naive UTC datetimes without 'Z'. Force UTC so the + // browser doesn't misinterpret them as local time (e.g. UTC+2 → 2h off). + const utcStr = startedAt.endsWith("Z") || startedAt.includes("+") ? startedAt : startedAt + "Z"; + const start = new Date(utcStr).getTime(); const tick = () => { const now = Date.now(); @@ -40,7 +43,8 @@ export default function LiveTimer({ let totalPaused = pausedSeconds; if (isPaused) { - const pauseStart = new Date(pausedAt!).getTime(); + const pausedAtUtc = pausedAt!.endsWith("Z") || pausedAt!.includes("+") ? pausedAt! : pausedAt! + "Z"; + const pauseStart = new Date(pausedAtUtc).getTime(); totalPaused += Math.floor((now - pauseStart) / 1000); }