github.com/geniusesgroup/libgo@v0.0.0-20220713101832-828057a9d3d4/time/monotonic/time.go (about) 1 /* For license and copyright information please see LEGAL file in repository */ 2 3 package monotonic 4 5 import ( 6 "sync/atomic" 7 8 "../../protocol" 9 ) 10 11 type Time struct { 12 sec int64 13 nsec int32 14 } 15 16 func (t *Time) Epoch() protocol.TimeEpoch { return protocol.TimeEpoch_Monotonic } 17 func (t *Time) SecondElapsed() int64 { return t.sec } 18 func (t *Time) NanoSecondElapsed() int32 { return t.nsec } 19 func (t *Time) ToString() string { 20 // TODO::: 21 return "" 22 } 23 24 func (t *Time) Now() { 25 var nsec = RuntimeNano() 26 var secElapsed = nsec / int64(Second) 27 t.sec = secElapsed 28 t.nsec = int32(nsec % (secElapsed * int64(Second))) 29 } 30 func (t *Time) NowAtomic() { 31 var nsec = RuntimeNano() 32 var secElapsed = nsec / int64(Second) 33 var nsecElapsed = nsec % (secElapsed * int64(Second)) 34 atomic.AddInt64(&t.sec, secElapsed) 35 atomic.AddInt32(&t.nsec, int32(nsecElapsed)) 36 } 37 38 func (t *Time) Pass(baseTime Time) (pass bool) { return } 39 func (t *Time) AddDuration(d protocol.Duration) (new Time) { return }