DevTools Logo
All posts

Counting a Streak Correctly Means Using Local Dates, Not UTC Timestamps

August 28, 2026 · DevTools

habits
streaks
productivity
timezones

A streak counter sounds trivial until timezones get involved — a habit-tracking app built on Date.toISOString() alone silently counts in UTC, which means a check-in logged at 11pm local time can land on the "wrong" calendar day for anyone west of UTC, breaking a real streak the user actually kept. The Habit & Streak Tracker builds its date keys from local year, month, and day fields specifically to avoid that bug.

Local date keys

Every check-in is stored as a YYYY-MM-DD key built from date.getFullYear(), date.getMonth(), and date.getDate() — the local-timezone accessors — rather than from an ISO string, which is UTC-based and would silently shift a late-evening check-in to the next (or previous) calendar day depending on the user's offset from UTC.

Counting backward from today

The streak length itself is computed by walking backward one day at a time from today, checking whether each local date key exists in the set of check-in days, and stopping the moment a day is missing. A streak of 12 means 12 consecutive local calendar days with a check-in, ending today or yesterday (a check-in isn't required yet today for the streak to still be "alive," but skip a day and it resets to zero on the next check).

Why this matters more than it sounds

Streak mechanics are one of the most effective habit-formation tools precisely because losing one feels costly — which is exactly why a streak counter that's wrong (resetting a real streak due to a timezone bug, or failing to reset a broken one) actively undermines the thing it's supposed to encourage. Getting the date-boundary logic right isn't a cosmetic detail here.

What to pair a streak with

A streak tracks consistency; it doesn't track content. For habits tied to a nightly routine, the Sleep Cycle Calculator helps keep the bedtime side of that routine consistent, and for a streak built around daily study rather than a general habit, the Flashcards & Spaced Repetition tool already tracks its own review-due schedule that a streak can wrap around.