mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-21 23:22:34 +01:00
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:
@@ -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))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user