Skip to content

Commit d65d1ff

Browse files
committed
Check for zero time instant in TimeStamp.IsZero() (go-gitea#22171)
- Backport of go-gitea#22171 - Currently, the 'IsZero' function for 'TimeStamp' just checks if the unix time is zero, which is not the behavior of 'Time.IsZero()', but Gitea is using this method in accordance with the behavior of 'Time.IsZero()'. - Adds a new condition to check for the zero time instant. - Fixes a bug where non-expiring GPG keys where shown as they expired on Jan 01, 0001. - Related https://codeberg.org/Codeberg/Community/issues/791
1 parent 72524ad commit d65d1ff

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Diff for: modules/timeutil/timestamp.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@ import (
1313
// TimeStamp defines a timestamp
1414
type TimeStamp int64
1515

16-
// mock is NOT concurrency-safe!!
17-
var mock time.Time
16+
var (
17+
// mock is NOT concurrency-safe!!
18+
mock time.Time
19+
20+
// Used for IsZero, to check if timestamp is the zero time instant.
21+
timeZeroUnix = time.Time{}.Unix()
22+
)
1823

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

104109
// IsZero is zero time
105110
func (ts TimeStamp) IsZero() bool {
106-
return int64(ts) == 0
111+
return int64(ts) == 0 || int64(ts) == timeZeroUnix
107112
}

0 commit comments

Comments
 (0)