aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorJohn Olheiser <john.olheiser@gmail.com>2021-10-18 15:12:26 -0500
committerGitHub <noreply@github.com>2021-10-18 21:12:26 +0100
commitc59afa752d9746af6d870635ce3baaaff67b8027 (patch)
tree0e85620735e6fcfaf0c7264b16deb63ddb5d1fd7 /modules
parentf0376b7e020f0e7a790e4ee801db17f1f4bcd994 (diff)
downloadgitea-c59afa752d9746af6d870635ce3baaaff67b8027.tar.gz
gitea-c59afa752d9746af6d870635ce3baaaff67b8027.zip
Allow mocking timeutil (#17354)
Signed-off-by: jolheiser <john.olheiser@gmail.com>
Diffstat (limited to 'modules')
-rw-r--r--modules/timeutil/timestamp.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/modules/timeutil/timestamp.go b/modules/timeutil/timestamp.go
index b1c60c3084..1fe8d4fcb1 100644
--- a/modules/timeutil/timestamp.go
+++ b/modules/timeutil/timestamp.go
@@ -13,8 +13,24 @@ import (
// TimeStamp defines a timestamp
type TimeStamp int64
+// mock is NOT concurrency-safe!!
+var mock time.Time
+
+// Set sets the time to a mocked time.Time
+func Set(now time.Time) {
+ mock = now
+}
+
+// Unset will unset the mocked time.Time
+func Unset() {
+ mock = time.Time{}
+}
+
// TimeStampNow returns now int64
func TimeStampNow() TimeStamp {
+ if !mock.IsZero() {
+ return TimeStamp(mock.Unix())
+ }
return TimeStamp(time.Now().Unix())
}