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

Comments

Projects
None yet
2 participants
@b-s-a
Copy link

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.