Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
During a backward clock change, chrono conversions discarded
datetime.foldand could collapse the two occurrences of a local time into one instant. For example, Los Angeles's two occurrences of2026-11-01 01:30reach C++ as the same time point, and returning the second occurrence from C++ producesfold=0with a Python timestamp one hour early.Use Python's datetime implementation to disambiguate local timestamps and determine the returned
fold. Preserve microseconds separately from whole-second timestamps to avoid floating-point precision loss. Reconstructing a base naive datetime preserves the documented handling oftzinfoand datetime subclasses. A narrow Windows fallback retains valid conversions during the first day after the Unix epoch, where Python's backward fold-detection probes cannot be represented by the Windows runtime.Add independent tests for both conversion directions, both folds, spring-gap normalization, half-hour and non-DST clock changes, negative timestamps, distant-date microsecond precision, input-field semantics, and early-epoch round trips. Update timezone tests to refresh and restore the process timezone with
time.tzset(), and document fold and gap behavior. Use named IANA zones on GraalPy, whose Java timezone parser does not support POSIX rule strings, and check known output wall times and fold values independently of Python conversion results. On GraalPy before 25.1, run timezone-dependent tests in fresh interpreters withTZset at startup: those releases cache their initial timezone aftertime.tzset(). Preserve child assertion failures and skips in the parent pytest results.This follows the fold-based approach discussed in #3805, prompted by James Unicomb's original report in #3451, and clarifies the local-time behavior raised in #1638. The original Sydney spring-gap example cannot round-trip its nonexistent wall time through an actual instant; it follows Python's documented gap normalization.
Local validation (GCC 13.3 / C++20, with incremental scons builds for regular and free-threaded CPython 3.14.4):
test_chrono.cpp, with the full repository configuration, C++17, CPython 3.12 headers, and warnings as errors: the twomodernize-use-autodiagnostics reproduce before the correction and the corrected header passes. CI uses clang-tidy 20.prek run -a --quietpassed.The skips cover unavailable SciPy and
<experimental/optional>, plus existing GIL/deadlock exclusions. Windows, PyPy, and 32-bit coverage will come from CI; Windows handling was reviewed against CPython's implementation.Suggested changelog entry:
datetime.foldon input and preserving it on returned datetimes. Preserve exact microseconds and document Python-compatible normalization of nonexistent local times.📚 Documentation preview 📚: https://pybind11--6202.org.readthedocs.build/