Skip to content

fix(insights): keep usage windows on the viewer's local hour - #8201

Merged
waleedlatif1 merged 1 commit into
stagingfrom
fix/usage-window-local-hour
Sep 23, 2026
Merged

waleedlatif1 merged 1 commit into
stagingfrom
fix/usage-window-local-hour

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Partial custom range falls back to the current period without dropping the viewer's timezone, so an unbounded (self-hosted) period's trailing window starts on the local hour and its first segment can settle and cache
  • The unbounded previous period now ends exactly where the current period's window starts, both ends on the viewer's hour — previously it was [now − 60d, now − 30d), which overlapped the current window by up to an hour and left two partial hours re-read on every view
  • Extracted startOfLocalHour so both windows share one alignment rule

Type of Change

  • Bug fix

Testing

  • Regression tests for both paths (Asia/Kolkata, half-hour offset); both fail against the previous code
  • Billing + Insights suites incl. real-Postgres: 1,187 passed
  • Lint, type-check, check:audits, docs-manifest, block registry all green

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Sep 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Sep 23, 2026 3:52pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge, with the changed window boundaries matching existing half-open query and local-hour segment contracts.

Summary

This PR consistently aligns unbounded usage windows to the viewer’s local hour.

  • Preserves the supplied timezone when an incomplete custom range falls back to the current period.
  • Makes unbounded previous and current windows adjacent under the existing half-open range semantics.
  • Extracts the shared local-hour alignment logic and adds regression coverage using a half-hour-offset timezone.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  N[Current instant] --> C[Align now - 30 days to viewer-local hour]
  C --> CW["Current window: [current.from, now)"]
  C --> P[Subtract another 30 days and align]
  P --> PW["Previous window: [previous.from, current.from)"]
Loading

Reviews (1) · Last reviewed commit: "fix(insights): keep usage windows on the..."

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/lib/billing/core/usage-analytics.ts
@waleedlatif1
waleedlatif1 merged commit d453d1b into staging Sep 23, 2026
61 of 62 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/usage-window-local-hour branch September 23, 2026 16:33

This branch was previously deployed

1 inactive deployment
Preview 07fe089e Deployed Sep 23, 2026 by vercel[bot]
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.

1 participant