Skip to content

Align hour buckets to the site time zone - #7

Merged
sinnercode228 merged 1 commit into
mainfrom
fix/hour-bucket-timezone
Oct 21, 2026
Merged

sinnercode228 merged 1 commit into
mainfrom
fix/hour-bucket-timezone

Conversation

@sinnercode228

Copy link
Copy Markdown
Owner

What was wrong
bucketStart() in packages/core/src/time.ts takes a timeZone but only applied it to day buckets. The 'hour' case was Math.floor(ts / HOUR) * HOUR, i.e. UTC-aligned. On a site whose zone has a half-hour offset (Asia/Kolkata, Asia/Tehran, Australia/Adelaide), hourly timeseries buckets landed 30 minutes off the local clock, and the range snapping in query.ts resolve() was off by the same amount.

The fix
Align the 'hour' case to the zone the same way startOfDay already does (shift by tzOffsetMinutes, floor to the hour, subtract the boundary offset back out). Minute buckets stay UTC-floored on purpose — every zone offset is a whole number of minutes, so local and UTC minute boundaries always coincide. nextBucket stays bucket + HOUR; for whole-hour zones that is still exact across DST, since the offset changes by a whole hour on an hour boundary.

How it was tested
Added a failing test (hour bucket in Asia/Kolkata should start at :30 past the UTC hour, plus the enumeration over a range), then the fix. A second test checks hour buckets stay one real hour apart across the America/New_York fall-back. Full suite, lint, format check, typecheck and build all pass.

Fixes #6

bucketStart() only used the timeZone for day buckets; the hour case
floored in UTC, so hourly timeseries on a half-offset zone (Asia/Kolkata,
Asia/Tehran) were 30 minutes off the local clock and the range snapping in
query.ts resolve() was off by the same amount. Align the hour case the way
startOfDay already does. Minute buckets stay UTC-floored because every zone
offset is a whole number of minutes.

Fixes #6
@sinnercode228
sinnercode228 merged commit 4da642b into main Oct 21, 2026
2 checks passed
@sinnercode228
sinnercode228 deleted the fix/hour-bucket-timezone branch October 21, 2026 07:22
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.

Hourly buckets ignore the site time zone

1 participant