From f51a19c537cbe63a9a670204c2c1c826af2506ed Mon Sep 17 00:00:00 2001 From: Gusted Date: Tue, 20 Dec 2022 03:07:41 +0100 Subject: [PATCH] Check for zero time instant in TimeStamp.IsZero() (#22171) (#22173) - Backport of #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 --- modules/timeutil/timestamp.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/timeutil/timestamp.go b/modules/timeutil/timestamp.go index d2a5fec50..e45039b96 100644 --- a/modules/timeutil/timestamp.go +++ b/modules/timeutil/timestamp.go @@ -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) { @@ -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 }