fix(timer): treat backend timestamps as UTC to fix 2h offset
Some checks failed
Aegis CI / lint-and-test (push) Has been cancelled
Some checks failed
Aegis CI / lint-and-test (push) Has been cancelled
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user