mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-02-26 16:57:08 +00:00
29 lines
477 B
Go
29 lines
477 B
Go
// Package ntp provide time.Now
|
|
//
|
|
// DON'T import other package in mihomo to keep minimal internal dependencies
|
|
package ntp
|
|
|
|
import (
|
|
"time"
|
|
|
|
"sync/atomic"
|
|
)
|
|
|
|
var _offset atomic.Int64 // [time.Duration]
|
|
|
|
func SetOffset(offset time.Duration) {
|
|
_offset.Store(int64(offset))
|
|
}
|
|
|
|
func GetOffset() time.Duration {
|
|
return time.Duration(_offset.Load())
|
|
}
|
|
|
|
func Now() time.Time {
|
|
now := time.Now()
|
|
if offset := GetOffset(); offset != 0 {
|
|
now = now.Add(offset)
|
|
}
|
|
return now
|
|
}
|