You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Binning temporal data using the built-in _hours_ interval forces interval boundaries to start at midnight #2452
I expected each bin to be the same size (maybe expect the very last one). Instead each day is individually divided into two bins of size 11 hours and one bin of size 2 hours.
The same happens for every interval of which 24 hours isn’t an integer multiple (i.e., 5, 7, 9, …).
This seems to be ultimately caused by the “statelessness” of the interval functions (floor, ceil, offset, etc.) They don’t know what their “zero value” should be and thus assume that it’s midnight. When binning with these strange time increments, this assumption doesn’t hold. (Though even with this explanation I don’t understand why the ceil function gets clamped at midnight.)
In order to provide the intended result, each bin would need to know the starting point of the first bin. This should probably be derived from the corresponding scale domain. Then it could correctly add increments of the specified duration until it finds its own extent.
Of course, these calculations could also be performed by the user who would then provide either a custom interval implementation or pre-computed thresholds. So I’m not sure if this bug needs fixing at all. However, I do believe that this behaviour at least warrants a documentation update. I was very surprised by Plot.timeInterval('65 minutes').ceil(new Date()).
Just for completeness’s sake:
timeInterval('90 seconds').ceil(newDate('2026-07-03T05:05:05Z')).toISOString()// "2026-07-03T05:06:00.000Z" – seconds intervals align and clamp at the minutetimeInterval('90 minutes').ceil(newDate('2026-07-03T05:05:05Z')).toISOString()// "2026-07-03T06:00:00.000Z" – minute intervals align and clamp at the hourtimeInterval('25 hours').ceil(newDate('2026-07-03T05:05:05Z')).toISOString()// "2026-07-03T22:00:00.000Z" – hour intervals align and clamp at the daytimeInterval('33 days').ceil(newDate('2026-07-03T05:05:05Z')).toISOString()// "2026-07-03T22:00:00.000Z" – day intervals align and clamp at the month// I have no clue what’s going on with weekstimeInterval('1 weeks').ceil(newDate('2026-07-03T05:05:05Z')).toISOString()// "2026-07-04T22:00:00.000Z"timeInterval('2 weeks').ceil(newDate('2026-07-03T05:05:05Z')).toISOString()// "2026-07-11T22:00:00.000Z"timeInterval('3 weeks').ceil(newDate('2026-07-03T05:05:05Z')).toISOString()// "2026-07-04T22:00:00.000Z"timeInterval('2 months').ceil(newDate('2026-07-03T05:05:05Z')).toISOString()// "2026-08-31T22:00:00.000Z" – month intervals align and clamp at the monthstimeInterval('2 years').ceil(newDate('2026-07-03T05:05:05Z')).toISOString()// "2027-12-31T23:00:00.000Z" – year intervals align and clamp at the years
Activity
mwaibel-go commentedon Aug 5, 2026
I believe I found the root cause or at least a related bug:
These two are 60 minutes apart, even though the interval’s
intervalDurationis 3900000 (= 65 minutes).More relevant to the example in the issue description,
is the next midnight.
This seems to be ultimately caused by the “statelessness” of the interval functions (floor, ceil, offset, etc.) They don’t know what their “zero value” should be and thus assume that it’s midnight. When binning with these strange time increments, this assumption doesn’t hold. (Though even with this explanation I don’t understand why the ceil function gets clamped at midnight.)
In order to provide the intended result, each bin would need to know the starting point of the first bin. This should probably be derived from the corresponding scale domain. Then it could correctly add increments of the specified duration until it finds its own extent.
Of course, these calculations could also be performed by the user who would then provide either a custom interval implementation or pre-computed thresholds. So I’m not sure if this bug needs fixing at all. However, I do believe that this behaviour at least warrants a documentation update. I was very surprised by
Plot.timeInterval('65 minutes').ceil(new Date()).Just for completeness’s sake: