How the Alarm Clock Decides When to Ring
AnyTool Alarm Clock rings by comparing the current local wall-clock time to each alarm on every tick, never by scheduling a single future timer that could drift while the tab sleeps. A one-second interval reads a fresh Date, derives the current HH:MM and weekday, and checks every enabled alarm: an alarm fires when its time string equals the current HH:MM, it is scheduled for today’s weekday (for repeats), and it has not already fired this minute. A per-alarm minute stamp (year-month-day-HH:MM) makes firing idempotent so an alarm rings at most once per matching minute even if several ticks land inside it. Because every tick re-reads the real time, the clock is self-correcting: if the tab is briefly throttled and the interval wakes late, it still detects and rings the alarm as soon as it runs within the matching minute. Snooze is modeled as a transient re-arm at a future epoch timestamp that the same loop watches.
- A 1s interval re-reads the live time every tick — no drifting pre-scheduled timer
- An enabled alarm fires when its HH:MM equals now and its weekday matches (for repeats)
- A per-minute stamp (Y-M-D-HH:MM) makes each firing idempotent (rings once per minute)
- Self-correcting after a throttle: it rings as soon as the loop runs within the matching minute
- Snooze is a transient re-arm at now + snoozeMinutes, watched by the same loop
