How the Chess Timer Keeps Accurate Time
AnyTool Chess Timer is timestamp-based rather than counter-based. Each side’s remaining time is banked in milliseconds, and when a side’s turn begins the clock records performance.now() as the turn-start timestamp. A requestAnimationFrame loop then displays the running side’s time as banked minus (now − turn start) on every frame, so the stored number only changes on a real event — a tap, a pause or a flag. This avoids the slow drift of a clock that subtracts a fixed amount on each animation frame, where uneven frame intervals and throttled background tabs accumulate error. Pausing banks the elapsed time exactly back into the store, and resuming records a fresh turn-start timestamp.
- Remaining time banked in milliseconds; only mutated on real events
- performance.now() captured at the start of each turn
- Displayed time = banked − (now − turn start), recomputed every frame
- No per-tick subtraction, so the clock cannot drift like a counter
- Pause banks elapsed time precisely; resume sets a new turn-start
