relativetime.go 359 B

123456789101112131415161718
  1. package timex
  2. import "time"
  3. // Use the long enough past time as start time, in case timex.Now() - lastTime equals 0.
  4. var initTime = time.Now().AddDate(-1, -1, -1)
  5. func Now() time.Duration {
  6. return time.Since(initTime)
  7. }
  8. func Since(d time.Duration) time.Duration {
  9. return time.Since(initTime) - d
  10. }
  11. func Time() time.Time {
  12. return initTime.Add(Now())
  13. }