游戏玩法游戏时长实现

This commit is contained in:
kercylan98
2023-04-27 10:49:30 +08:00
parent edb2c0e21f
commit 861dd7ecef
5 changed files with 168 additions and 1 deletions

24
utils/offset/time.go Normal file
View 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)
}