12345678910111213141516171819202122 |
- 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
- }
- // Time returns current time, the same as time.Now().
- func Time() time.Time {
- return initTime.Add(Now())
- }
|