fix(time): handle Sunday correctly in TimeWeekStart

On Sunday, Weekday() returns 0, causing (0-1)*-24 = +24 hours which
jumped forward to next Monday instead of back to last Monday. This
affected any weekly reset logic running on Sundays.
This commit is contained in:
Houmgaor
2026-02-08 00:55:43 +01:00
parent 072d3b895d
commit e08d6af992

View File

@@ -16,7 +16,11 @@ func TimeMidnight() time.Time {
func TimeWeekStart() time.Time {
midnight := TimeMidnight()
offset := (int(midnight.Weekday()) - 1) * -24
weekday := int(midnight.Weekday())
if weekday == 0 {
weekday = 7 // Treat Sunday as day 7
}
offset := (weekday - 1) * -24
return midnight.Add(time.Hour * time.Duration(offset))
}