Our system recently experienced a bug because of the surprise that sits 
(documented) inside of time.Truncate() 
<https://pkg.go.dev/time#Time.Truncate>:

"""
Truncate operates on the time as an absolute duration since the zero time; 
it does not operate on the presentation form of the time. Thus, 
Truncate(Hour) may return a time with a non-zero minute, depending on the 
time's Location.
"""

Example of this surprise: https://go.dev/play/p/hZEHhj8QTZs
currentTime: 2021-07-28 06:03:00 +0545 +0545
truncated to one hour: 2021-07-28 05:45:00 +0545 +0545
truncateTimezoneSensitive: 2021-07-28 06:00:00 +0545 +0545

I see that time: could use a "truncate in timezone" feature 
<https://github.com/golang/go/issues/10894> was closed a long time ago with 
the comment: "The vast majority of truncation/rounding of times happens on 
units of 1 hour or smaller, and those are typically not sensitive to time 
zone." I do agree that most rounding/truncating does work on one hour or 
less (we sure do), but I'd say that it should be sensitive to time zones. 
The over a billion people in India (GMT +5:30) would agree with that, as 
they are the ones that reported the bug in our system.

I would like to suggest this for an addition to the Go says WAT? 
<https://about.sourcegraph.com/blog/go/gophercon-2018-go-says-wat>
 collection.

Can someone re-open the bug for further discussion?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/304a1365-9d9e-46f2-92bd-349a60182f5en%40googlegroups.com.

Reply via email to