diff --git a/internal/manager/sleep_scheduler/calculations.go b/internal/manager/sleep_scheduler/calculations.go index f0d2d238..fd2f8160 100644 --- a/internal/manager/sleep_scheduler/calculations.go +++ b/internal/manager/sleep_scheduler/calculations.go @@ -60,7 +60,7 @@ func calculateNextCheck(now time.Time, schedule *persistence.SleepSchedule) time // calcNext returns the given time of day on "today" if that hasn't passed // yet, otherwise on "tomorrow". calcNext := func(tod persistence.TimeOfDay) time.Time { - nextCheck := tod.OnDate(now) + nextCheck := tod.OnDate(now).In(time.Local) if nextCheck.Before(now) { nextCheck = nextCheck.AddDate(0, 0, 1) } @@ -99,5 +99,6 @@ func earliestTime(timestamps []time.Time) time.Time { // endOfDay returns the next midnight at UTC. func endOfDay(now time.Time) time.Time { - return time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.UTC).AddDate(0, 0, 1) + startOfDay := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local) + return startOfDay.AddDate(0, 0, 1) } diff --git a/internal/manager/sleep_scheduler/sleep_scheduler_test.go b/internal/manager/sleep_scheduler/sleep_scheduler_test.go index 95872130..6dc0f44c 100644 --- a/internal/manager/sleep_scheduler/sleep_scheduler_test.go +++ b/internal/manager/sleep_scheduler/sleep_scheduler_test.go @@ -256,13 +256,14 @@ type TestMocks struct { // to the given time. Seconds and sub-seconds are set to zero. func (m *TestMocks) todayAt(hour, minute int) time.Time { now := m.clock.Now() - return time.Date(now.Year(), now.Month(), now.Day(), hour, minute, 0, 0, now.Location()) + todayAt := time.Date(now.Year(), now.Month(), now.Day(), hour, minute, 0, 0, time.Local) + return todayAt } // endOfDay returns midnight of the day after whatever the mocked clock's "now" is set to. func (m *TestMocks) endOfDay() time.Time { - now := m.clock.Now().UTC() - return time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()).AddDate(0, 0, 1) + startOfToday := m.todayAt(0, 0) + return startOfToday.AddDate(0, 0, 1) } func testFixtures(t *testing.T) (*SleepScheduler, TestMocks, context.Context) {