github.com/ari-anchor/sei-tendermint@v0.0.0-20230519144642-dc826b7b56bb/libs/time/time.go (about)

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