fix(statusline): use configured timezone for today cost#970
Conversation
📝 WalkthroughWalkthroughThis PR fixes issue ChangesStatusline Timezone-Aware Date Filtering
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.Comment |
Statusline previously computed today with Date.toISOString(), which always uses UTC. Users whose local or configured timezone had crossed a different calendar day could see $0.00 today because daily usage was bucketed in another timezone. Compute the filter date through the same timezone-aware formatter used for daily grouping, pass the timezone into loadDailyUsageData, and add regression coverage for ryoppippi#778.
c70ab32 to
dcc6197
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/ccusage/src/commands/statusline.ts (1)
141-185: ⚡ Quick winSwitch this regression test to
createFixture().The manual
mkdtempSync/writeFileSyncsetup bypasses the repo’s standard Claude-data fixture helper and makes this test harder to keep consistent with other ccusage tests. As per coding guidelines, use fs-fixture with createFixture() to simulate Claude data in tests.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/ccusage/src/commands/statusline.ts` around lines 141 - 185, Replace the manual temp-dir and file setup (mkdtempSync, mkdirSync, writeFileSync, rmSync) with the repo's fs-fixture createFixture() helper: create a fixture that mirrors the previous layout (a .claude/projects/test-project/session-123.jsonl file containing the same JSONL line), then call loadDailyUsageData(...) and calculateTotals(...) as before; rely on createFixture() to handle fixture creation and cleanup and remove the manual mkdtempSync/mkdirSync/writeFileSync/rmSync logic so the test uses the standard createFixture() flow.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/ccusage/src/commands/statusline.ts`:
- Around line 141-185: Replace the manual temp-dir and file setup (mkdtempSync,
mkdirSync, writeFileSync, rmSync) with the repo's fs-fixture createFixture()
helper: create a fixture that mirrors the previous layout (a
.claude/projects/test-project/session-123.jsonl file containing the same JSONL
line), then call loadDailyUsageData(...) and calculateTotals(...) as before;
rely on createFixture() to handle fixture creation and cleanup and remove the
manual mkdtempSync/mkdirSync/writeFileSync/rmSync logic so the test uses the
standard createFixture() flow.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: c6d363dc-bbc7-4235-85e5-4e0574f4ea2a
📒 Files selected for processing (2)
apps/ccusage/config-schema.jsonapps/ccusage/src/commands/statusline.ts
Fixes #778.
Summary
statuslinecomputed today's date withDate.toISOString(), which always uses UTC. Daily usage is grouped using the local or configured timezone, so users far from UTC could see$0.00 todayduring date-boundary windows.This changes statusline to compute the today filter with the same timezone-aware formatter used by daily grouping, passes that timezone into
loadDailyUsageData, and exposes--timezoneon the statusline command.Verification
pnpm --filter ccusage run formatpnpm --filter ccusage typecheckpnpm --filter ccusage run testgit diff --check origin/main...HEADSummary by CodeRabbit
Release Notes