Skip to content

fix(statusline): use configured timezone for today cost#970

Open
aukaukauk wants to merge 1 commit into
ryoppippi:mainfrom
aukaukauk:codex/fix-statusline-today-timezone
Open

fix(statusline): use configured timezone for today cost#970
aukaukauk wants to merge 1 commit into
ryoppippi:mainfrom
aukaukauk:codex/fix-statusline-today-timezone

Conversation

@aukaukauk
Copy link
Copy Markdown

@aukaukauk aukaukauk commented May 2, 2026

Fixes #778.

Summary

statusline computed today's date with Date.toISOString(), which always uses UTC. Daily usage is grouped using the local or configured timezone, so users far from UTC could see $0.00 today during 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 --timezone on the statusline command.

Verification

  • pnpm --filter ccusage run format
  • pnpm --filter ccusage typecheck
  • pnpm --filter ccusage run test
  • git diff --check origin/main...HEAD

Summary by CodeRabbit

Release Notes

  • New Features
    • Added timezone configuration setting to statusline. This enables accurate date grouping and filtering based on your specified timezone instead of the system default, ensuring proper daily usage tracking across different regions.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 2, 2026

📝 Walkthrough

Walkthrough

This PR fixes issue #778 by adding timezone-aware "today" date filtering to the statusline command. A new getTodayDateFilter() helper replaces UTC-based string derivation, the config schema adds a timezone setting, and the statusline command now threads this timezone through to daily usage calculations.

Changes

Statusline Timezone-Aware Date Filtering

Layer / File(s) Summary
Config Schema
apps/ccusage/config-schema.json
Added timezone string property to statusline configuration schema with documentation noting it controls date grouping and defaults to system timezone.
Date Filter Helper
apps/ccusage/src/commands/statusline.ts (lines 110–190)
Introduced getTodayDateFilter(timezone?) helper that computes YYYYMMDD "today" string using formatDate() with the provided timezone instead of UTC-based toISOString() derivation.
Command Integration
apps/ccusage/src/commands/statusline.ts (lines 1–19, 243, 422–432)
Updated imports to include date formatting utilities and filesystem helpers; added timezone: sharedArgs.timezone to CLI arguments; passed mergedOptions.timezone to getTodayDateFilter() and loadDailyUsageData() for timezone-aligned cost filtering.
Tests & Validation
apps/ccusage/src/commands/statusline.ts (lines 110–190)
Added guarded vitest tests validating timezone behavior across UTC, non-UTC, and boundary-crossing timezones; regression checks ensure timezone-aligned filtering preserves or excludes matching daily cost correctly.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • ryoppippi

Poem

🐰 Hops with joy, whiskers twitching in the light
UTC was wrong, now timezones align just right!
Perth's day is no longer lost to midnight's sight,
"Today" at last shows truth—no more zero blight! 🌍✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: making statusline use the configured timezone for computing today's cost, directly addressing the core issue in PR #970.
Linked Issues check ✅ Passed The PR fully addresses issue #778 by implementing timezone-aware computation for today's date, passing timezone through to daily usage loading, and exposing the --timezone CLI option.
Out of Scope Changes check ✅ Passed All changes (config schema update, timezone-aware helper, CLI argument addition, and test coverage) are directly aligned with fixing the statusline timezone issue in #778.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

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.
@aukaukauk aukaukauk force-pushed the codex/fix-statusline-today-timezone branch from c70ab32 to dcc6197 Compare May 2, 2026 07:31
@aukaukauk aukaukauk marked this pull request as ready for review May 2, 2026 10:53
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
apps/ccusage/src/commands/statusline.ts (1)

141-185: ⚡ Quick win

Switch this regression test to createFixture().

The manual mkdtempSync/writeFileSync setup 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

📥 Commits

Reviewing files that changed from the base of the PR and between 1a4bd69 and dcc6197.

📒 Files selected for processing (2)
  • apps/ccusage/config-schema.json
  • apps/ccusage/src/commands/statusline.ts

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.

Statusline "today" shows $0.00 due to timezone defaulting to UTC

1 participant