Skip to content

Fix astimezone conversion with dateutil timezones - #1006

Open
ryanchou1994 wants to merge 1 commit into
python-pendulum:masterfrom
ryanchou1994:fix/astimezone-dateutil
Open

Fix astimezone conversion with dateutil timezones#1006
ryanchou1994 wants to merge 1 commit into
python-pendulum:masterfrom
ryanchou1994:fix/astimezone-dateutil

Conversation

@ryanchou1994

Copy link
Copy Markdown

astimezone() can lose its timezone or return the wrong wall time when the target is a dateutil timezone. Its fromutc() implementation performs datetime arithmetic, which currently dispatches into Pendulum's duration arithmetic.

Perform the conversion on a native datetime first, then use the existing reconstruction to preserve the Pendulum subclass, target timezone and fold. No new dependency or API is added.

Fixes #820.

Pull Request Check List

  • Added tests for changed code.
  • Updated documentation for changed code. N/A: restores the existing datetime-compatible behavior.

Validation: the new regression matrix fails in 38 cases before the fix and passes afterward. On Linux with Python 3.11, the full suite passes with both pure-Python and native extensions (1,925 passed, 3 skipped each); mypy and the applicable Python lint/format hooks also pass. The matrix covers dateutil, built-in, ZoneInfo and Pendulum timezones, DST folds, naive inputs, local-time conversion and a subclass.

Copilot AI lite review requested due to automatic review settings September 9, 2026 09:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pendulum.instance & dateutil.tz compatibility

2 participants