Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid infinite loop in CalendarIntervalTrigger with UTC timezone #898

Merged
merged 6 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading