-
Notifications
You must be signed in to change notification settings - Fork 18k
time: inconsistent result for Date when date is created during DST #50223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
time.Date()
explainations required when date is created during DST
As the documentation said, "it does not guarantee which." So this may be working as intended. Thanks. cc @rsc @ianlancetaylor for if there is anything that could be improved. |
Thanks for the bug report, but the function is behaving as documented and intended. |
Thanks for the answer, but could you please be more specific ? I agree it's documented this way but I don't understand how this behavior could be intended. Without fixing this bug how could we deal to get the current day (for example) for a given timestamp ? I think you will agree the following code produces a wrong result, right ? santiago, _ := time.LoadLocation("America/Santiago")
t := time.Date(2021, 9, 5, 0, 0, 0, 0, santiago)
fmt.Printf("day in santiago: %d (expecting 5)\n", t.Day()) // day in santiago: 4 (expecting 5), this is truely problematic What could be the reason(s) why this behavior would be intended please ? |
You are calling You presumably do have a reason to prefer one or the other, and now that you are aware of the problem you can check for it in your code and make your code do the right thing for your use case. But that doesn't mean that there is an obviously correct answer for all uses for (I'll note that it's unfortunate that Chile has chosen to do time zone transitions at midnight. Most countries do time zone transitions at 2am to somewhat reduce, though certainly not eliminate, this class of problems.) |
Thank you for taking time to respond (in whatever timezone you are), it's crystal clear now. The Chile's choice is indeed very infortunate.. I think we can find a satisfying-ish workaround since the following code works as expected:
|
What version of Go are you using (
go version
)?go version go1.17 linux/amd64
Does this issue reproduce with the latest release?
Yes
What did you do?
Inconsistent time creation on DST (a similar problem is reported in issue #41272)
For local time that does not exist, and for different DST, time is not created the same way:
The documentation is explicit (but not helpful)
It seems (without any deep investigation) that the creation of a "skipped" time:
Example, see go-playground
What did you expect to see?
I expected a similar creation for all times that are created in a DST
Or, at least, a deterministic attribute / value / algo to predict if the conversion will lead before or after DST
What did you see instead?
I see what the documentation explains : an un-guaranteed result which leads to unexpected behaviors when a date is created in a DST
The text was updated successfully, but these errors were encountered: