github.com/xmplusdev/xmcore@v1.8.11-0.20240412132628-5518b55526af/common/protocol/time.go (about) 1 package protocol 2 3 import ( 4 "time" 5 6 "github.com/xmplusdev/xmcore/common/dice" 7 ) 8 9 type Timestamp int64 10 11 type TimestampGenerator func() Timestamp 12 13 func NowTime() Timestamp { 14 return Timestamp(time.Now().Unix()) 15 } 16 17 func NewTimestampGenerator(base Timestamp, delta int) TimestampGenerator { 18 return func() Timestamp { 19 rangeInDelta := dice.Roll(delta*2) - delta 20 return base + Timestamp(rangeInDelta) 21 } 22 }