mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
380e1a0ae2
* fix(tests): fix flaky time-based tests * test: replace time package with a mock Using a dedicated dependency would have been awesome, but i try to keep this repo with minimal dependencies
34 lines
478 B
Go
34 lines
478 B
Go
//nolint:revive
|
|
package xtime
|
|
|
|
import "time"
|
|
|
|
var clock Clock = &RealClock{}
|
|
|
|
func SetClock(c Clock) {
|
|
clock = c
|
|
}
|
|
|
|
func Now() time.Time {
|
|
return clock.Now()
|
|
}
|
|
|
|
func Since(t time.Time) time.Duration {
|
|
return clock.Since(t)
|
|
}
|
|
|
|
func Until(t time.Time) time.Duration {
|
|
return clock.Until(t)
|
|
}
|
|
|
|
func Sleep(d time.Duration) {
|
|
clock.Sleep(d)
|
|
}
|
|
|
|
type Clock interface {
|
|
Now() time.Time
|
|
Since(t time.Time) time.Duration
|
|
Until(t time.Time) time.Duration
|
|
Sleep(d time.Duration)
|
|
}
|