25 lines
411 B
Go
25 lines
411 B
Go
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)
|
|
}
|