How the Pomodoro Timer Keeps Accurate Time
AnyTool Pomodoro Timer is timestamp-based rather than counter-based. When a phase starts, the timer records the wall-clock end time as Date.now() plus the remaining milliseconds; a requestAnimationFrame loop then displays remaining = endTime − Date.now() on every frame and only repaints — it never decrements a stored counter. Because the displayed time is always derived from that single timestamp, the countdown cannot accumulate the drift of a per-tick subtraction, and it is self-correcting: if the tab is throttled in the background and the loop wakes up late, it computes the true remaining time from the timestamp and fires the phase-end transition immediately if the end time has already passed. Pausing banks the exact remaining milliseconds and resuming sets a fresh end time, and the browser tab title shows a live mm:ss countdown for the current phase.
- endTime = Date.now() + remaining is recorded when a phase starts
- Displayed time = endTime − Date.now(), recomputed every frame
- No per-tick subtraction, so the countdown cannot drift like a counter
- Self-correcting after a background throttle — true remaining is recomputed from the timestamp
- Pause banks exact remaining ms; the tab title shows a live mm:ss countdown
