Skip to content

Streaks not counting in time zones far away from HST - #44

Open
kabeleh wants to merge 1 commit into
KateCatlin:mainfrom
kabeleh:main
Open

Streaks not counting in time zones far away from HST#44
kabeleh wants to merge 1 commit into
KateCatlin:mainfrom
kabeleh:main

Conversation

@kabeleh

@kabeleh kabeleh commented May 11, 2026

Copy link
Copy Markdown
Contributor

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)

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant