From 54ee8762c39efb59abafeea64ca615db0163f62e Mon Sep 17 00:00:00 2001 From: Krisztian Gacsal Date: Tue, 13 Aug 2024 13:31:54 +0200 Subject: [PATCH] fix: strip monotonic clock reading from time returned by clock Remove monotonic time reading from time.Time returned by clock.Now(). This change help with comparing time.Time objects where one of them are generated by clock.Now() by forcing Go to use only the wall clock time for comparing them. --- pkg/clock/clock.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/clock/clock.go b/pkg/clock/clock.go index 1f68a130c..df548f3f0 100644 --- a/pkg/clock/clock.go +++ b/pkg/clock/clock.go @@ -5,7 +5,8 @@ import "time" var drift time.Duration func Now() time.Time { - return time.Now().Add(-drift) + t := time.Now().Add(-drift) + return t.Round(0) // Remove monotonic time reading } func SetTime(t time.Time) time.Time {