Skip to content

Commit

Permalink
Avoid infinite loop in CalendarIntervalTrigger with UTC timezone (#898)
Browse files Browse the repository at this point in the history
Fixes #897.
  • Loading branch information
unights committed Apr 25, 2024
1 parent d9df123 commit b5dfbed
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/versionhistory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ APScheduler, see the :doc:`migration section <migration>`.
- Fixed JSON serialization of triggers that had been used at least once
- Fixed dialect name checks in the SQLAlchemy job store
- Fixed JSON and CBOR serializers unable to serialize enums
- Fixed infinite loop in CalendarIntervalTrigger with UTC timezone (PR by unights)

**4.0.0a4**

Expand Down
2 changes: 1 addition & 1 deletion src/apscheduler/triggers/calendarinterval.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def next(self) -> datetime | None:
next_time = datetime.fromtimestamp(timestamp, self.timezone)

# Check if the time is off due to normalization and a forward DST shift
if next_time.time() != self._time:
if next_time.timetz() != self._time:
previous_date = next_time.date()
else:
self._last_fire_date = next_date
Expand Down
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ def timezone() -> ZoneInfo:
return ZoneInfo("Europe/Berlin")


@pytest.fixture(scope="session")
def utc_timezone() -> ZoneInfo:
return ZoneInfo("UTC")


@pytest.fixture(
params=[
pytest.param(PickleSerializer, id="pickle"),
Expand Down
7 changes: 7 additions & 0 deletions tests/triggers/test_calendarinterval.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,10 @@ def test_repr(timezone, serializer):
"time='03:00:08', start_date='2016-03-05', end_date='2020-12-25', "
"timezone='Europe/Berlin')"
)


def test_utc_timezone(utc_timezone):
trigger = CalendarIntervalTrigger(
days=1, hour=1, start_date=date(2016, 3, 31), timezone=utc_timezone
)
assert trigger.next() == datetime(2016, 3, 31, 1, tzinfo=utc_timezone)

0 comments on commit b5dfbed

Please sign in to comment.