Skip to content

Fix/usage timezone handling#3086

Open
IamCoder18 wants to merge 3 commits intoKilo-Org:mainfrom
IamCoder18:fix/usage-timezone-handling
Open

Fix/usage timezone handling#3086
IamCoder18 wants to merge 3 commits intoKilo-Org:mainfrom
IamCoder18:fix/usage-timezone-handling

Conversation

@IamCoder18
Copy link
Copy Markdown

Summary

Fix timezone handling in the usage tab so dates are grouped by the user's local timezone instead of UTC. This affects "By Day", "By Model & Day" views, streak calculation, and streak calendar.

Changes:

  • API route /api/profile/usage now accepts timeZone parameter and uses PostgreSQL AT TIME ZONE for timezone-aware date grouping
  • Client detects browser timezone via Intl.DateTimeFormat().resolvedOptions().timeZone
  • Streak calculation and calendar data generation now use toLocaleDateString('en-CA', { timeZone }) for correct local date formatting
  • Initial timezone state is null to defer query until browser timezone is detected

Visual Changes

N/A - functionality fix, dates now correctly reflect user's local timezone.

Reviewer Notes

  • The en-CA locale is used because it formats dates as YYYY-MM-DD by default
  • Added isValidTimezone() function to validate IANA timezone strings and prevent SQL injection
  • API falls back to UTC if invalid or missing timezone parameter

Comment thread apps/web/src/app/api/profile/usage/route.ts Outdated
Comment thread apps/web/src/app/(app)/usage/page.tsx Outdated
@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented May 7, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • apps/web/src/app/(app)/usage/page.tsx
  • apps/web/src/app/api/profile/usage/route.ts

Reviewed by gpt-5.5-20260423 · 310,160 tokens

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