Skip to content

Commit 40ba750

Browse files
authored
Check for zero time instant in TimeStamp.IsZero() (#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 Before: ![image](https://user-images.githubusercontent.com/25481501/208509035-ecc5fa4a-3bd1-4fa3-beba-90875719163c.png) After: ![image](https://user-images.githubusercontent.com/25481501/208508950-3e7f6eeb-be83-432a-89a6-d738553dafe4.png)
1 parent 2774671 commit 40ba750

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
@@ -12,8 +12,13 @@ import (
1212
// TimeStamp defines a timestamp
1313
type TimeStamp int64
1414

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

1823
// Set sets the time to a mocked time.Time
1924
func Set(now time.Time) {
@@ -102,5 +107,5 @@ func (ts TimeStamp) FormatDate() string {
102107

103108
// IsZero is zero time
104109
func (ts TimeStamp) IsZero() bool {
105-
return int64(ts) == 0
110+
return int64(ts) == 0 || int64(ts) == timeZeroUnix
106111
}

0 commit comments

Comments
 (0)