go-zero/core/timex/relativetime.go

18 lines
482 B
Go
Raw Normal View History

2020-07-26 17:09:05 +08:00
package timex
import "time"
// Use the long enough past time as start time, in case timex.Now() - lastTime equals 0.
var initTime = time.Now().AddDate(-1, -1, -1)
2021-02-24 16:27:11 +08:00
// Now returns a relative time duration since initTime, which is not important.
// The caller only needs to care about the relative value.
2020-07-26 17:09:05 +08:00
func Now() time.Duration {
return time.Since(initTime)
}
2021-02-24 16:27:11 +08:00
// Since returns a diff since given d.
2020-07-26 17:09:05 +08:00
func Since(d time.Duration) time.Duration {
return time.Since(initTime) - d
}