mirror of
https://github.com/netbirdio/netbird.git
synced 2025-08-09 23:27:58 +02:00
[client] Fix elapsed time calculation when machine is in sleep mode (#4140)
This commit is contained in:
@ -9,6 +9,8 @@ var (
|
||||
baseWallNano int64
|
||||
)
|
||||
|
||||
type Time int64
|
||||
|
||||
func init() {
|
||||
baseWallTime = time.Now()
|
||||
baseWallNano = baseWallTime.UnixNano()
|
||||
@ -23,7 +25,11 @@ func init() {
|
||||
// and using time.Since() for elapsed calculation, this avoids repeated
|
||||
// time.Now() calls and leverages Go's internal monotonic clock for
|
||||
// efficient duration measurement.
|
||||
func Now() int64 {
|
||||
func Now() Time {
|
||||
elapsed := time.Since(baseWallTime)
|
||||
return baseWallNano + int64(elapsed)
|
||||
return Time(baseWallNano + int64(elapsed))
|
||||
}
|
||||
|
||||
func Since(t Time) time.Duration {
|
||||
return time.Duration(Now() - t)
|
||||
}
|
||||
|
Reference in New Issue
Block a user