github.com/sandwich-go/boost@v1.3.29/z/wall.go (about)

     1  package z
     2  
     3  import "time"
     4  
     5  type wallClock struct {
     6  	t      time.Time
     7  	offset time.Duration
     8  }
     9  
    10  var wc wallClock
    11  
    12  func init() {
    13  	wc = wallClock{t: time.Now(), offset: offset()}
    14  }
    15  
    16  // Now returns the current wall clock time.
    17  func Now() time.Time {
    18  	return wc.t.Add(offset() - wc.offset)
    19  }
    20  
    21  // NowWithOffset returns the wall clock time with given offset.
    22  func NowWithOffset(monoOffset time.Duration) time.Time {
    23  	return wc.t.Add(monoOffset - wc.offset)
    24  }
    25  
    26  func offset() time.Duration {
    27  	return time.Duration(runtimeNanotime())
    28  }