-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
time: time.Unix(0, 0).IsZero() == false #33597
Comments
This is working as intended and documented: https://golang.org/pkg/time/#Time Even if we wanted to change it, we couldn't at this point for go1compat reasons. Go's time.Time zero value is not the Unix epoch zero value. The |
@bradfitz Can fix it on go2 |
@runner-mei We could change it in a v2 of the time package, but we aren't going to do that. See the discussion at https://golang.org/src/time/time.go?#L346. |
I use this instead |
add IsUnixZero()? |
I don't think this comes up often enough to need a special function or method. |
I'm aware that IsZero is implemented with year 1, Jan 1 being 'zero'. (https://golang.org/pkg/time/#Time.IsZero) However, it causes confusion when most developers use epoch time at 0, and the IsZero function is then false for
time.Unix(0,0)
.Why is zero time considered year 1, Jan 1 instead of epoch 0?
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://play.golang.org/p/NtsWcGMJMaU
What did you expect to see?
IsZero evaluates to
true
for the beginning of epoch time. I'm unsure what the compelling reason for deviating from typical standards is.What did you see instead?
Using epoch time within my applications and golang requires special consideration and it does not work as expected. I feel the deviation is unnecessarily complicated, though now would be a breaking change so we cannot just change it now.
The text was updated successfully, but these errors were encountered: