Skip to content

Preserve endpoint folds when calculating interval components - #1029

Open
FanWu-ai wants to merge 1 commit into
python-pendulum:masterfrom
FanWu-ai:fix-interval-endpoint-folds
Open

FanWu-ai wants to merge 1 commit into
python-pendulum:masterfrom
FanWu-ai:fix-interval-endpoint-folds

Conversation

@FanWu-ai

@FanWu-ai FanWu-ai commented Oct 5, 2026

Copy link
Copy Markdown

Interval.__init__ reconstructs the endpoints for precise_diff without their fold values. This changes the UTC offset during a repeated DST hour, even though Interval.__new__ preserves the fold for the total duration.

For example, New York on 2024-11-03, 01:15 with fold=0 to 01:45 with fold=1, currently has total_seconds() == 5400 but reports (hours, minutes) == (0, 30) and in_words() == "30 minutes".

Pass each original fold to the corresponding reconstruction, matching __new__. The interval then correctly reports one hour and thirty minutes. Tests cover both endpoints, signed/reversed/absolute intervals, and same-fold controls.

Pull Request Check List

  • Added tests for changed code: 12 failures on the old implementation in each backend; 20 new cases including controls
  • Full native-extension suite: 1870 passed, 3 upstream skips
  • Full pure-Python suite: 1870 passed, 3 upstream skips
  • Mypy: 228 source files, no issues
  • All prek hooks, including Rust formatting/clippy, passed
  • Documentation: no API change; preserving existing endpoint metadata

The untouched baseline passed the same checks before editing. Validation used Python 3.12.14, the real Rust extension, and locked dependencies. This is a fold-preservation fix; the separate same-wall-time datetime comparison issue discussed in #351 is outside its scope.

Independently reviewed and rechecked with both full backends, mypy, and every prek hook.

Prepared with OpenAI Codex assistance.

@FanWu-ai
FanWu-ai marked this pull request as ready for review October 5, 2026 05:47

This branch has not been deployed

No deployments
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.

1 participant