feat(usage): add month-to-date range - #9108
Closed
andersryanc wants to merge 1 commit into
Closed
Conversation
Contributor
ApprovabilityVerdict: Not approved Macroscope's review found this PR not approvable — This PR adds a new month-to-date usage and estimated-cost view across web and mobile, backed by shared runtime date-window logic. Existing defaults remain unchanged, but the cross-surface production behavior and limited UI-level coverage merit human review. You can add or adjust custom eligibility rules. Learn more. |
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Changed
Added an MTD (month to date) option to the Usage page on web, desktop, and mobile.
The new range covers the first day of the current month through today using the user’s local time zone. Refreshing the page also recalculates the range when the day or month changes.
Why
The existing 30-day range is a rolling window, so it can include usage from the previous month. This makes it harder for API-billed users to estimate their current monthly spend.
MTD provides a calendar-aligned view of usage and estimated API costs for the current month.
UI Changes
Before
After
Verification
Checklist
Note
Low Risk
Scoped UI and date-window helpers for usage display; no auth, billing, or data-pipeline changes beyond existing usage queries.
Overview
Adds an MTD period to Usage on web and mobile so totals and charts use the first day of the current calendar month through today in the viewer’s local time zone, instead of only rolling day windows.
Shared
makeMonthToDateWindowbuilds that daily-resolution window (reusingmakeWindowfor “today” and timezone, then settingsinceDaytoYYYY-MM-01). Period selectors now use avalueofnumber | "mtd"withmakeWindowForPeriod, including on refresh when the calendar day rolls over. Web period toggles/selects resolve options by string value so MTD is not coerced withNumber(). User docs and a timezone-focused unit test cover the new range.Reviewed by Cursor Bugbot for commit 2f15c83. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Add month-to-date range option to usage screens
makeMonthToDateWindow(now?)in usageFormat.ts which builds a daily-resolution window from the first day of the current month to today in the viewer's time zone{ days, window }to{ period, window }whereperiodis a union of numbers and'mtd'makeWindowForPeriodhelper on both platforms that delegates tomakeMonthToDateWindow()for MTD and preserves hourly resolution for 24h and daily resolution for other numeric rangesWINDOW_OPTIONSentries now usevalueinstead ofdays; any code referencing the olddaysfield on these options will need updatingMacroscope summarized 2f15c83.