Skip to content

Fix timezone handling for non-UTC users#186

Merged
iamtoruk merged 1 commit intomainfrom
fix/menubar-timezone-184
May 1, 2026
Merged

Fix timezone handling for non-UTC users#186
iamtoruk merged 1 commit intomainfrom
fix/menubar-timezone-184

Conversation

@iamtoruk
Copy link
Copy Markdown
Member

@iamtoruk iamtoruk commented May 1, 2026

Summary

  • Menubar UTC bug: computeHistoryStats in FindingsSection.swift hardcoded TimeZone(identifier: "UTC") and effectiveTokensInLast7Days in AppStore.swift used ISO8601DateFormatter() (UTC default). Both now use .current to match the CLI's local-timezone date keys. This caused streaks, week deltas, and projections to be off by a day for non-UTC users.
  • --timezone flag: New global --timezone <zone> option (and CODEBURN_TZ env var) lets users override the system timezone for all date grouping. Sets process.env.TZ before any Date operations so all existing code works unchanged. Useful for Docker, CI, cron, or viewing data in a different timezone.
  • DST spring-forward fix: Replaced todayStart.getTime() - MS_PER_DAY with new Date(y, m, d - 1) for yesterday/backfill computations. Subtracting 86400000ms from midnight skips a day on DST spring-forward (23-hour day).

Test plan

  • npx tsx src/cli.ts report --period today --format json --timezone Asia/Singapore outputs correct local date
  • npx tsx src/cli.ts report --period today --format json --timezone Asia/Seoul outputs correct local date
  • npx tsx src/cli.ts report --timezone InvalidZone prints error and exits 1
  • CODEBURN_TZ=Asia/Tokyo npx tsx src/cli.ts report --period today --format json picks up env var
  • npx tsc --noEmit passes
  • swift build passes for menubar app

Fixes #184

Three fixes for issue #184:

1. Menubar Swift code used UTC instead of local timezone in two places:
   computeHistoryStats hardcoded TimeZone("UTC") and
   effectiveTokensInLast7Days used ISO8601DateFormatter (UTC default).
   Both now use .current to match CLI-produced local date keys.

2. Add --timezone flag and CODEBURN_TZ env var to override the system
   timezone for all date grouping. Sets process.env.TZ before any Date
   operations so all existing local-timezone code works unchanged.

3. Replace MS_PER_DAY arithmetic with Date constructor day-of-month
   math for yesterday/backfill computations. Subtracting 86400000ms
   from midnight skips a day on DST spring-forward (23-hour day).

Fixes #184
@iamtoruk iamtoruk merged commit 78ad04c into main May 1, 2026
3 checks passed
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.

Today period uses UTC date instead of local timezone — wrong 'today' for non-UTC users

1 participant