Skip to content

fix(billing): parse usage dates as local time in billing-usage charts - #3411

Merged
baktun14 merged 3 commits into
mainfrom
fix/billing-trend-indicator-today-timezone
Jul 13, 2026
Merged

fix(billing): parse usage dates as local time in billing-usage charts#3411
baktun14 merged 3 commits into
mainfrom
fix/billing-trend-indicator-today-timezone

Conversation

@baktun14

@baktun14 baktun14 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Why

The usage history date field arrives from the API as a YYYY-MM-DD date-only string. Several billing-usage components parsed it with native new Date(...), which interprets a bare date as UTC midnight. Comparing/formatting that instant in local time shifts it a day for any user west of UTC:

  • TrendIndicatorisToday() misfired, so the "today" label was wrongly hidden for western-hemisphere users.
  • CumulativeSpendingLineChart — the X-axis tick labels and the tooltip date were rendered one day early (e.g. 7/1 shown as 6/30).

This also made the TrendIndicator "today" spec fail intermittently depending on the runner's timezone.

What

  • Parse the date-only string with date-fns parseISO, which reads date-only ISO strings in local time, so date comparisons and labels are consistent in every timezone.
  • Added timezone-pinned tests for the chart formatters (asserting identical output under America/Los_Angeles and Asia/Tokyo); verified they fail on the old new Date() code (6/30 vs 7/1). The existing TrendIndicator spec now passes deterministically across timezones.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed billing usage chart date handling by switching to date-only parsing for consistent axis and tooltip formatting in the viewer’s local timezone.
    • Improved “today” detection in trend indicators for date-only values.
    • Kept unparseable date strings from being reformatted incorrectly.
  • Tests
    • Added unit tests to confirm axis tick and tooltip labels render identically across different TZ settings, including the unparseable-date case.

The usage history date arrives as a YYYY-MM-DD string. Parsing it with
native new Date() treats it as UTC midnight, so isToday() misfired for
users west of UTC and the 'today' label was wrongly hidden. parseISO
reads date-only strings as local time, fixing the label and making the
TrendIndicator test deterministic across timezones.
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: df2f022e-00f3-45a1-8403-9c32f42a128f

📥 Commits

Reviewing files that changed from the base of the PR and between 23804ee and 4f1ebf3.

📒 Files selected for processing (1)
  • apps/deploy-web/src/components/billing-usage/CumulativeSpendingLineChart/CumulativeSpendingLineChart.spec.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/deploy-web/src/components/billing-usage/CumulativeSpendingLineChart/CumulativeSpendingLineChart.spec.tsx

📝 Walkthrough

Walkthrough

Billing usage trend checks and cumulative spending chart labels now parse date-only strings with parseISO, with tests confirming timezone-independent formatting and invalid-date handling.

Changes

Billing usage date handling

Layer / File(s) Summary
Current-day date parsing
apps/deploy-web/src/components/billing-usage/TrendIndicator/TrendIndicator.tsx
TrendIndicator uses parseISO before checking whether the latest date is today, replacing direct Date construction for date-only values.
Chart date formatting and validation
apps/deploy-web/src/components/billing-usage/CumulativeSpendingLineChart/CumulativeSpendingLineChart.tsx, apps/deploy-web/src/components/billing-usage/CumulativeSpendingLineChart/CumulativeSpendingLineChart.spec.tsx
Chart axis and tooltip formatters use local date-only parsing, with tests covering timezone-invariant output, invalid-date passthrough, and temporary timezone restoration.

Estimated code review effort: 2 (Simple) | ~10 minutes

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/billing-trend-indicator-today-timezone

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

@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.03%. Comparing base (a72c94b) to head (4f1ebf3).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3411      +/-   ##
==========================================
- Coverage   72.06%   71.03%   -1.03%     
==========================================
  Files        1155     1065      -90     
  Lines       29324    26991    -2333     
  Branches     7231     6779     -452     
==========================================
- Hits        21133    19174    -1959     
+ Misses       7201     6861     -340     
+ Partials      990      956      -34     
Flag Coverage Δ *Carryforward flag
api 85.59% <ø> (ø) Carriedforward from 23804ee
deploy-web 60.84% <100.00%> (+0.03%) ⬆️
log-collector ?
notifications 91.44% <ø> (ø) Carriedforward from 23804ee
provider-console 81.38% <ø> (ø) Carriedforward from 23804ee
provider-inventory ?
provider-proxy 86.42% <ø> (ø) Carriedforward from 23804ee
tx-signer ?

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
...eSpendingLineChart/CumulativeSpendingLineChart.tsx 100.00% <100.00%> (+46.15%) ⬆️
...ts/billing-usage/TrendIndicator/TrendIndicator.tsx 100.00% <100.00%> (ø)

... and 91 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The axis tick and tooltip formatters parsed the YYYY-MM-DD usage date
with native new Date(), which reads it as UTC midnight. format() then
renders in local time, so axis labels and tooltip dates were off by one
day for users west of UTC. Switch to parseISO (local time) and cover
both formatters with timezone-pinned tests.
@baktun14 baktun14 changed the title fix(billing): parse usage date as local time in TrendIndicator fix(billing): parse usage dates as local time in billing-usage charts Jul 10, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@apps/deploy-web/src/components/billing-usage/CumulativeSpendingLineChart/CumulativeSpendingLineChart.spec.tsx`:
- Around line 56-63: Update the `withTimezone` helper to restore
`process.env.TZ` correctly: when the original value is `undefined`, delete
`process.env.TZ`; otherwise restore the original string value in the `finally`
block.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 82558026-7d5c-4670-a2e4-fe7441a29f34

📥 Commits

Reviewing files that changed from the base of the PR and between f1d6d57 and 23804ee.

📒 Files selected for processing (2)
  • apps/deploy-web/src/components/billing-usage/CumulativeSpendingLineChart/CumulativeSpendingLineChart.spec.tsx
  • apps/deploy-web/src/components/billing-usage/CumulativeSpendingLineChart/CumulativeSpendingLineChart.tsx

@github-actions github-actions Bot added size: S and removed size: XS labels Jul 11, 2026
@baktun14
baktun14 added this pull request to the merge queue Jul 13, 2026
Merged via the queue into main with commit c51a091 Jul 13, 2026
57 checks passed
@baktun14
baktun14 deleted the fix/billing-trend-indicator-today-timezone branch July 13, 2026 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants