-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Description
At present the nearest thing to this proposal is func (t Time) Round(d Duration) Time.
The problem with that function is that it is essentially a simple mathematical round. There is no option to take an origin timestamp into account.
What I am suggesting is something closer to, for example, the PostgreSQL date_bin function. I have copy/pasted the examples from the PG website to give you a feel:
SELECT date_bin('15 minutes', TIMESTAMP '2020-02-11 15:44:17', TIMESTAMP '2001-01-01');
Result: 2020-02-11 15:30:00
SELECT date_bin('15 minutes', TIMESTAMP '2020-02-11 15:44:17', TIMESTAMP '2001-01-01 00:02:30');
Result: 2020-02-11 15:32:30
The present Go behaviour is closer to the first example (i.e. 15:44:17 gets rounded to the nearest 15 minute, i.e. 15:30:00).
However Go has no stdlib functionality to achieve what is shown in the second example (i.e. 15:44:17 gets rounded to 15:32:30 because the base "origin" is defined as 00:02:30 and therefore the 15 minute bins are calculated on the basis of 00:02:30 instead of 00:00:00).