Skip to content
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: Add IsNull() function for Time struct #28351

Closed
b-s-a opened this issue Oct 24, 2018 · 2 comments
Closed

time: Add IsNull() function for Time struct #28351

b-s-a opened this issue Oct 24, 2018 · 2 comments

Comments

@b-s-a
Copy link

@b-s-a b-s-a commented Oct 24, 2018

Current Time structure has no method like IsNull() (Valid() or something else) so you need to use t.Equal(time.Time{}) or pointers to check is time defined or not (for example, when you aquire values from external sources and some of them may be omited). Usage of pointers for such small object has known overhead, so I propose to add function IsNull() which returns true for uninitialized time structure (1970-01-01 00:00:00).

@agnivade
Copy link
Contributor

@agnivade agnivade commented Oct 24, 2018

https://golang.org/pkg/time/#Time

The zero value of type Time is January 1, year 1, 00:00:00.000000000 UTC. As this time is unlikely to come up in practice, the IsZero method gives a simple way of detecting a time that has not been initialized explicitly.

@b-s-a
Copy link
Author

@b-s-a b-s-a commented Oct 24, 2018

Oh sorry. I many times tries to find IsNull, but cannot find IsZero. Thank you.

@b-s-a b-s-a closed this Oct 24, 2018
@golang golang locked and limited conversation to collaborators Oct 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.