You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
786 B

  1. package time
  2. import (
  3. "time"
  4. )
  5. // Now returns the current time in UTC with no monotonic component.
  6. func Now() time.Time {
  7. return Canonical(time.Now())
  8. }
  9. // Canonical returns UTC time with no monotonic component.
  10. // Stripping the monotonic component is for time equality.
  11. // See https://github.com/tendermint/tendermint/pull/2203#discussion_r215064334
  12. func Canonical(t time.Time) time.Time {
  13. return t.Round(0).UTC()
  14. }
  15. //go:generate ../../scripts/mockery_generate.sh Source
  16. // Source is an interface that defines a way to fetch the current time.
  17. type Source interface {
  18. Now() time.Time
  19. }
  20. // DefaultSource implements the Source interface using the system clock provided by the standard library.
  21. type DefaultSource struct{}
  22. func (DefaultSource) Now() time.Time {
  23. return Now()
  24. }