Skip to content

Commit

Permalink
timer: Fix wrong execution dated in At timer when current date is in …
Browse files Browse the repository at this point in the history
…week 1 of the next year
  • Loading branch information
mhthies committed Dec 30, 2024
1 parent a17ec56 commit 7ba94fc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion shc/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def limit(i: int, val: List[int]) -> int:
- datetime.timedelta(days=1)).day

if self.week_mode:
val = [now.year, now.isocalendar()[1], now.isocalendar()[2], now.hour, now.minute, now.second,
val = [now.isocalendar()[0], now.isocalendar()[1], now.isocalendar()[2], now.hour, now.minute, now.second,
round(now.microsecond / 1000)]
else:
val = [now.year, now.month, now.day, now.hour, now.minute, now.second, round(now.microsecond / 1000)]
Expand Down
5 changes: 5 additions & 0 deletions test/test_timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ def test_simple_next(self) -> None:
once_timer = timer.At(weeknum=15)
self._assert_datetime(datetime.datetime(2020, 4, 6, 0, 0, 0), once_timer._next_execution())

def test_2024_bug(self) -> None:
with ClockMock(datetime.datetime(2024, 12, 30, 14, 26, 17)):
at_timer = shc.timer.At(weekday=[1, 2, 3, 4, 5], hour=6, minute=10)
self._assert_datetime(datetime.datetime(2024, 12, 31, 6, 10), at_timer._next_execution())

def test_spec_forms(self) -> None:
with ClockMock(datetime.datetime(2020, 1, 1, 15, 7, 17)):
once_timer = timer.At(hour=timer.EveryNth(2))
Expand Down

0 comments on commit 7ba94fc

Please sign in to comment.