diff options
Diffstat (limited to 'modules/timeutil')
-rw-r--r-- | modules/timeutil/timestamp.go | 16 |
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()) } |