github.com/scaleft/monotime@v0.0.0-20180209174256-2da272f3dad0/monotime_go19.go (about)

     1  // +build go1.9
     2  
     3  package monotime
     4  
     5  import (
     6  	"time"
     7  )
     8  
     9  type Monotime = time.Time
    10  
    11  type timer struct {
    12  	start Monotime
    13  }
    14  
    15  func newTimer() *timer {
    16  	return &timer{
    17  		start: time.Now(),
    18  	}
    19  }
    20  
    21  func (t *timer) Elapsed() time.Duration {
    22  	return time.Now().Sub(t.start)
    23  }
    24  
    25  func monotime() Monotime {
    26  	return time.Now()
    27  }
    28  
    29  func duration(start Monotime, end Monotime) time.Duration {
    30  	return end.Sub(start)
    31  }