From 31ad65d711f34c9cc00700a0358811f139c9f00f Mon Sep 17 00:00:00 2001 From: idanoo Date: Mon, 13 Feb 2023 08:15:45 +1300 Subject: [PATCH] Make sure we don't get todays values --- internal/gomastodonstats/utils.go | 1 + test.go | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 test.go diff --git a/internal/gomastodonstats/utils.go b/internal/gomastodonstats/utils.go index 74fd8d1..85576c4 100644 --- a/internal/gomastodonstats/utils.go +++ b/internal/gomastodonstats/utils.go @@ -22,6 +22,7 @@ func getStartofDayMonday() time.Time { } // Iterate until Monday! t := time.Now().In(localTime) + t = t.AddDate(0, 0, -1) for t.Weekday() != time.Monday { t = t.AddDate(0, 0, -1) } diff --git a/test.go b/test.go new file mode 100644 index 0000000..a451184 --- /dev/null +++ b/test.go @@ -0,0 +1,20 @@ +package main + +import ( + "log" + "time" +) + +func main() { + localTime, err := time.LoadLocation("Pacific/Auckland") + if err != nil { + log.Fatal(err) + } + // Iterate until Monday! + t := time.Now().In(localTime) + for t.Weekday() != time.Monday { + t = t.AddDate(0, 0, -1) + } + year, month, day := t.Date() + log.Println(time.Date(year, month, day, 0, 0, 0, 0, t.Location())) +}