游戏玩法游戏时长实现
This commit is contained in:
24
utils/offset/time.go
Normal file
24
utils/offset/time.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package offset
|
||||
|
||||
import "time"
|
||||
|
||||
func NewTime(offset time.Duration) *Time {
|
||||
return &Time{offset: offset}
|
||||
}
|
||||
|
||||
// Time 带有偏移量的时间
|
||||
type Time struct {
|
||||
offset time.Duration
|
||||
}
|
||||
|
||||
func (slf *Time) SetOffset(offset time.Duration) {
|
||||
slf.offset = offset
|
||||
}
|
||||
|
||||
func (slf *Time) Now() time.Time {
|
||||
return time.Now().Add(slf.offset)
|
||||
}
|
||||
|
||||
func (slf *Time) Since(t time.Time) time.Duration {
|
||||
return slf.Now().Sub(t)
|
||||
}
|
||||
Reference in New Issue
Block a user