Streaks not counting in time zones far away from HST - #44
Open
kabeleh wants to merge 1 commit into
Open
Conversation
The streak bug came from parsing HST date strings in the player’s local timezone when computing “yesterday.” For users ahead of Hawaii (for example Australia), this shifted yesterday by an extra day. What was wrong: In supabaseStats.ts:366, the old logic effectively did local-time parsing of a date-only HST string before subtracting a day. That made streak logic timezone-dependent instead of HST-dependent. Why only some players were affected: The bug depends on local timezone offset. Unaffected zones (HST, UTC, US West) often still got correct yesterday. Zones ahead of HST (especially UTC+8 to UTC+12) could get yesterday as two days back, or miss streak if played daily. Changes implemented: 1. Added HST-safe day shifting utility utils.ts:32. New helper: shiftHSTDate(baseDate, dayOffset). It parses with explicit HST offset (-10:00), so behavior is stable regardless of user locale. 2. Patched Supabase streak update path (supabaseStats.ts:366) and replaced local parse/subtract with shiftHSTDate(today, -1). 3. Patched local fallback yesterday helper (utils.ts:44) and getYesterdayInHST now uses shiftHSTDate, which also hardens local-storage streak logic paths. 4. Additional timezone hardening (related high-risk paths) in puzzles.ts:4074 puzzles.ts:4111 Archive.tsx:84 These prevent HST day-number/date rendering drift in certain timezones (not the main streak bug, but same root class). 5. Added repeatable regression script validate-streak-timezones.mjs:1 and npm script in package.json:12: validate:streak-timezones Reproduction and proof (before vs after) I reproduced the bug before patch with timezone simulation: Australia/Sydney: buggy yesterday = 2026-05-09 for playedDate 2026-05-11 consecutive day result = 1 (wrong) misses day result = 2 (wrong) After patch: Australia/Sydney: fixed yesterday = 2026-05-10 consecutive day result = 2 (correct) missed day result = 1 (correct) Co-authored-by: Copilot <copilot@github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The streak bug came from parsing HST date strings in the player’s local timezone when computing “yesterday.” For users ahead of Hawaii (for example Australia), this shifted yesterday by an extra day.
What was wrong:
In supabaseStats.ts:366, the old logic effectively did local-time parsing of a date-only HST string before subtracting a day. That made streak logic timezone-dependent instead of HST-dependent.
Why only some players were affected:
The bug depends on local timezone offset.
Unaffected zones (HST, UTC, US West) often still got correct yesterday. Zones ahead of HST (especially UTC+8 to UTC+12) could get yesterday as two days back, or miss streak if played daily.
Changes implemented:
Added HST-safe day shifting utility utils.ts:32. New helper: shiftHSTDate(baseDate, dayOffset). It parses with explicit HST offset (-10:00), so behavior is stable regardless of user locale.
Patched Supabase streak update path (supabaseStats.ts:366) and replaced local parse/subtract with shiftHSTDate(today, -1).
Patched local fallback yesterday helper (utils.ts:44) and getYesterdayInHST now uses shiftHSTDate, which also hardens local-storage streak logic paths.
Additional timezone hardening (related high-risk paths) in puzzles.ts:4074
puzzles.ts:4111
Archive.tsx:84
These prevent HST day-number/date rendering drift in certain timezones (not the main streak bug, but same root class).
Added repeatable regression script validate-streak-timezones.mjs:1 and npm script in package.json:12: validate:streak-timezones
Reproduction and proof (before vs after)
I reproduced the bug before patch with timezone simulation: Australia/Sydney:
buggy yesterday = 2026-05-09 for playedDate 2026-05-11 consecutive day result = 1 (wrong)
misses day result = 2 (wrong)
After patch:
Australia/Sydney:
fixed yesterday = 2026-05-10
consecutive day result = 2 (correct)
missed day result = 1 (correct)