Skip to content

Preserve fold in DateTime.time() - #1056

Open
AryanRG wants to merge 1 commit into
python-pendulum:masterfrom
AryanRG:fix/datetime-time-preserve-fold
Open

AryanRG wants to merge 1 commit into
python-pendulum:masterfrom
AryanRG:fix/datetime-time-preserve-fold

Conversation

@AryanRG

@AryanRG AryanRG commented Oct 17, 2026

Copy link
Copy Markdown

DateTime.time() drops fold=1, unlike datetime.datetime.time(). Recombining the extracted time with the original date and timezone can therefore change the instant: one hour earlier during New York's rollback, or 30 minutes earlier during Lord Howe's rollback.

Pass self.fold to the existing Time constructor. Twelve regression cases cover both folds, naive/UTC/named-zone extraction, clock fields and microseconds, the naive Time return value, and timestamp-preserving reconstruction across both rollbacks.

Validation on macOS arm64 / Python 3.12.15:

  • Full pure-Python suite (PENDULUM_EXTENSIONS=0, importing this checkout): 1,882 passed, 3 skipped (one Windows-only test and two existing zoneinfo limitations).
  • Ruff lint/format and full Mypy: passed (228 files).
  • Changed-file prek hooks and git diff --check: passed.

Native-extension build/tests and Rust checks were not run because cargo and rustc are unavailable. Other platforms and Python versions were not tested locally.

Pull Request Check List

  • Added tests for changed code.
  • Updated documentation for changed code.

No documentation change: this restores the inherited datetime.time() fold-preservation contract without adding an API.

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