18 lines
482 B
Go
18 lines
482 B
Go
|
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)
|
||
|
|
||
|
// Now returns a relative time duration since initTime, which is not important.
|
||
|
// The caller only needs to care about the relative value.
|
||
|
func Now() time.Duration {
|
||
|
return time.Since(initTime)
|
||
|
}
|
||
|
|
||
|
// Since returns a diff since given d.
|
||
|
func Since(d time.Duration) time.Duration {
|
||
|
return time.Since(initTime) - d
|
||
|
}
|