Fix: streak badge ignores user timezone#3086
Open
Aryanshravan wants to merge 5 commits into
Open
Conversation
GSSoC Label Checklist 🏷️@Priyanshu-byte-coder — please apply the appropriate labels before merging: Difficulty (pick one):
Quality (optional):
Validation (required to score):
|
Owner
|
CI is red (Build, Type check, Playwright) and the diff bundles unrelated leaderboard changes from #3010. Please rebase so this contains only the streak-badge timezone fix with green CI — the fix itself is in scope. |
Owner
|
Timezone-correct streak badges is worth fixing, but CI is red — Type check and Build fail on this branch. Fix those ( |
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.
Fixes #3027
What
The streak SVG badge endpoint (
/api/badge/streak-shield) always calculatedthe current streak using UTC day boundaries, while the dashboard's streak
endpoint (
/api/metrics/streak) correctly uses the user's stored timezone.This caused the publicly embedded README badge to disagree with the
dashboard, particularly for users far from UTC around midnight.
Root cause
fetchStreak()insrc/app/api/badge/streak-shield/route.tscalledcalculateStreakFromDates(activeDates)without atimeZoneargument, so itsilently defaulted to
"UTC"— unlike other callers of the same function(
/api/metrics/streak,public-profile-data.ts,consistency-score.ts),which all correctly resolve and pass the user's stored timezone.
Fix
resolveUserTimeZone(), which looks up the user's storedtimezonefrom Supabase by GitHub username (github_login).fetchStreak()now accepts atimeZoneparameter (default"UTC") andpasses it through to
calculateStreakFromDates(activeDates, new Set(), timeZone).GEThandler resolves the timezone before callingfetchStreak."UTC"if the user has no DevTrack account, hasno timezone set, or if the lookup fails for any reason — so the badge
never breaks for unauthenticated/public lookups.
Testing
Added
test/streak-shield-timezone.test.ts, covering:unavailable), and still returns a 200 response.
Acceptance criteria
user/timezone.