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

Check for zero time instant in TimeStamp.IsZero() (#22171) #22173

Merged
merged 1 commit into from
Dec 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions modules/timeutil/timestamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ import (
// TimeStamp defines a timestamp
type TimeStamp int64

// mock is NOT concurrency-safe!!
var mock time.Time
var (
// mock is NOT concurrency-safe!!
mock time.Time

// Used for IsZero, to check if timestamp is the zero time instant.
timeZeroUnix = time.Time{}.Unix()
)

// Set sets the time to a mocked time.Time
func Set(now time.Time) {
Expand Down Expand Up @@ -103,5 +108,5 @@ func (ts TimeStamp) FormatDate() string {

// IsZero is zero time
func (ts TimeStamp) IsZero() bool {
return int64(ts) == 0
return int64(ts) == 0 || int64(ts) == timeZeroUnix
}