fix(billing): parse usage dates as local time in billing-usage charts - #3411
Conversation
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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughBilling usage trend checks and cumulative spending chart labels now parse date-only strings with ChangesBilling usage date handling
Estimated code review effort: 2 (Simple) | ~10 minutes ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 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
*This pull request uses carry forward flags. Click here to find out more.
🚀 New features to boost your workflow:
|
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.
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
apps/deploy-web/src/components/billing-usage/CumulativeSpendingLineChart/CumulativeSpendingLineChart.spec.tsxapps/deploy-web/src/components/billing-usage/CumulativeSpendingLineChart/CumulativeSpendingLineChart.tsx
Why
The usage history
datefield arrives from the API as aYYYY-MM-DDdate-only string. Several billing-usage components parsed it with nativenew 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:isToday()misfired, so the "today" label was wrongly hidden for western-hemisphere users.7/1shown as6/30).This also made the
TrendIndicator"today" spec fail intermittently depending on the runner's timezone.What
parseISO, which reads date-only ISO strings in local time, so date comparisons and labels are consistent in every timezone.tickFormatter+ tooltiplabelFormatter)America/Los_AngelesandAsia/Tokyo); verified they fail on the oldnew Date()code (6/30vs7/1). The existingTrendIndicatorspec now passes deterministically across timezones.Summary by CodeRabbit
TZsettings, including the unparseable-date case.