From c6d66ebb46963b17abc5a0d486bc7b0a106379e0 Mon Sep 17 00:00:00 2001 From: c9s Date: Sat, 26 Jun 2021 20:09:26 +0800 Subject: [PATCH] util: add BeginningOfTheDay function --- pkg/util/time.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/util/time.go b/pkg/util/time.go index 67a24d1f6..5671a602d 100644 --- a/pkg/util/time.go +++ b/pkg/util/time.go @@ -9,3 +9,9 @@ func MillisecondsJitter(d time.Duration, jitterInMilliseconds int) time.Duration n := rand.Intn(jitterInMilliseconds) return d + time.Duration(n)*time.Millisecond } + +func BeginningOfTheDay(t time.Time) time.Time { + year, month, day := t.Date() + return time.Date(year, month, day, 0, 0, 0, 0, t.Location()) +} +