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
proposal: time: add IsUnixEpoch method to test whether a time is the Unix epoch #46974
Comments
Note that the time package's epoch is simply You say an // UnixEpoch returns the start of the Unix epoch in UTC.
func UnixEpoch() time.Time {
return time.Unix(0, 0).UTC()
} Is that correct? If that is correct, it's not clear to me that that is useful enough by itself. How often does this come up? When do you need the Unix epoch value as a |
I encountered this problem while writing an embedded application for a 3D printer. We manufacture separate resin cartridges for these 3D printers, and these cartridges have little EEPROMs onboard that store usage statistics. One of the statistics we need to store is the date that the cartridge was first used, because the material has a short shelf life. We store this value in the units I made a bug in this case by using time.IsZero() as opposed to a comparison with time.Unix(0, 0).UTC(). Given that time.IsZero already exists, I think that it would be very reasonable to provide an time.isEpoch function as a convenience for people who write software that interoperates with other systems that do use the unix epoch as the zero time value. I think that listing |
Thanks for the example. Honestly that seems kind of specific to me. I don't see why many people would use the suggested |
My final comment is that the IsZero method never should have existed because time is an affine space type. There's a reason every other language uses the word epoch |
The |
go version go1.15.6 darwin/amd64
Does this issue reproduce with the latest release?
Yes
What did you do?
This is just an opinion, but I think that the the time library should provide a simpler method for getting the Epoch time.
I was surprised by this:
Upon further inspection I realized that I needed to do
time.Unix(0, 0).UTC()
to get the epoch value becausetime.Unix()
is timezone aware. Given that the API already has atime.isZero()
method, I think there should be a method for fetching the environment's epoch value directly, without using a parsing method or a timezone aware method.The text was updated successfully, but these errors were encountered: