feat(usage): anchor day/hour grid to each user's actual reset time#139
Open
jonasnobile wants to merge 1 commit into
Open
feat(usage): anchor day/hour grid to each user's actual reset time#139jonasnobile wants to merge 1 commit into
jonasnobile wants to merge 1 commit into
Conversation
The usage-bar grid previously split the bar into N even segments, which only *coincidentally* lined up with day/hour boundaries for clean windows — it was not derived from the reset at all, and drifted for any other reset time, for non-integer windows (e.g. Codex 30d/1d), and across DST. Compute boundaries from the real reset timestamp with jiff calendar arithmetic instead, so blocks land on the user's own reset time-of-day (a Sun 12:00 weekly reset yields noon-to-noon day blocks) and stay correct across DST. The current-segment highlight now uses the same boundaries, so it always marks the real "today"/"this hour" block. - Claude: thread the raw ISO reset + window length through TierUsage; Session uses hour granularity, the 7-day tiers use day granularity. - Codex: add jiff; derive boundaries from the epoch reset_at + window_seconds, picking hour/day granularity per window (sub-hour windows get no grid). - Long windows step by a whole multiple of the unit so a thin bar stays legible while remaining reset-anchored. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Summary
Follow-up to #137. The usage-bar grid was a plain even split (
i / segments), which only coincidentally lined up with day/hour boundaries for clean windows — it wasn't actually derived from the reset. It drifted for any other reset time, for non-integer windows (Codex 30d → 14 even blocks, 1d → 12 even blocks), and across DST.Now boundaries are computed from the real reset timestamp using
jiffcalendar arithmetic, so blocks land on the user's own reset time-of-day. ASun 12:00weekly reset yields noon-to-noon day blocks; a user whose reset isWed 03:00gets blocks anchored there. The current-segment highlight uses the same boundaries, so it always marks the real "today" / "this hour" block.Changes
TierUsage. Session → hour granularity; the 7-day tiers → day granularity. Newreset_aligned_segments()returns the divider fractions + current-block range.jiff; derive boundaries from the epochreset_at+window_seconds, choosing hour/day granularity per window (segment_unit_for_window); sub-hour windows get no grid.segments_for_windowtest withsegment_unit_for_window+reset_aligned_segmentstests (guards + weekly-window invariants).Notes
Test plan
cargo build(pinned 1.95.0 toolchain) — both cratescargo clippy— cleancargo test— 28 pass🤖 Generated with Claude Code