[client] Fix elapsed time calculation when machine is in sleep mode (#4140)

This commit is contained in:
Zoltan Papp
2025-07-12 11:10:45 +02:00
committed by GitHub
parent a76c8eafb4
commit 3e6eede152
15 changed files with 62 additions and 42 deletions

View File

@ -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)
}