Skip to content

Fix: streak badge ignores user timezone#3086

Open
Aryanshravan wants to merge 5 commits into
Priyanshu-byte-coder:mainfrom
Aryanshravan:fix/streak-badge-timezone
Open

Fix: streak badge ignores user timezone#3086
Aryanshravan wants to merge 5 commits into
Priyanshu-byte-coder:mainfrom
Aryanshravan:fix/streak-badge-timezone

Conversation

@Aryanshravan

Copy link
Copy Markdown
Contributor

Fixes #3027

What

The streak SVG badge endpoint (/api/badge/streak-shield) always calculated
the 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() in src/app/api/badge/streak-shield/route.ts called
calculateStreakFromDates(activeDates) without a timeZone argument, so it
silently 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

  • Added resolveUserTimeZone(), which looks up the user's stored
    timezone from Supabase by GitHub username (github_login).
  • fetchStreak() now accepts a timeZone parameter (default "UTC") and
    passes it through to calculateStreakFromDates(activeDates, new Set(), timeZone).
  • The GET handler resolves the timezone before calling fetchStreak.
  • Falls back gracefully to "UTC" if the user has no DevTrack account, has
    no 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:

  • Badge correctly uses the user's stored timezone (not UTC) when set.
  • Badge falls back to UTC when the user/timezone isn't found.
  • Badge falls back to UTC gracefully if the timezone lookup throws (DB
    unavailable), and still returns a 200 response.

Acceptance criteria

  • Badge streak count matches dashboard streak count for the same
    user/timezone.
  • Unset/unknown timezone falls back to UTC without erroring.
  • Existing badge rate-limiting and error-handling behavior unaffected.
  • Test added covering timezone-aware badge streak calculation.

@github-actions github-actions Bot added gssoc26 GSSoC 2026 contribution type:bug GSSoC type bonus: bug fix type:testing GSSoC type bonus: tests (+10 pts) labels Jul 3, 2026
@github-actions github-actions Bot added type:feature GSSoC type bonus: new feature type:performance GSSoC type bonus: performance (+15 pts) labels Jul 3, 2026
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

GSSoC Label Checklist 🏷️

@Priyanshu-byte-coder — please apply the appropriate labels before merging:

Difficulty (pick one):

  • level:beginner — 20 pts
  • level:intermediate — 35 pts
  • level:advanced — 55 pts
  • level:critical — 80 pts

Quality (optional):

  • quality:clean — ×1.2 multiplier
  • quality:exceptional — ×1.5 multiplier

Validation (required to score):

  • gssoc:approved — counts for points
  • gssoc:invalid / gssoc:spam / gssoc:ai-slop — does not score

Type labels (type:*) are auto-detected from files and title. Review and adjust if needed.
Points formula: (difficulty × quality_multiplier) + type_bonus

@Priyanshu-byte-coder

Copy link
Copy Markdown
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.

@Priyanshu-byte-coder

Copy link
Copy Markdown
Owner

Timezone-correct streak badges is worth fixing, but CI is red — Type check and Build fail on this branch. Fix those (pnpm type-check && pnpm build clean locally) and push; then I'll review the timezone logic against the badge endpoints.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc26 GSSoC 2026 contribution type:bug GSSoC type bonus: bug fix type:feature GSSoC type bonus: new feature type:performance GSSoC type bonus: performance (+15 pts) type:testing GSSoC type bonus: tests (+10 pts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Streak badge (/api/badge/streak-shield) ignores user timezone, disagrees with dashboard streak

2 participants