Repository navigation
Align hour buckets to the site time zone - #7
Merged
Merged
Conversation
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
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 was wrong
bucketStart()in packages/core/src/time.ts takes atimeZonebut only applied it to day buckets. The 'hour' case wasMath.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 inquery.tsresolve()was off by the same amount.The fix
Align the 'hour' case to the zone the same way
startOfDayalready does (shift bytzOffsetMinutes, 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.nextBucketstaysbucket + 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