Repository navigation
Add lossless DateTime reconstruction from nanosecond timestamps - #37
Merged
Merged
Conversation
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.
Closes #36.
Adds
DateTime::from_unix_timestamp_nanos(i128)and PythonDateTime.from_unix_timestamp_nanos(nanos: int), allowingfrom_unix_timestamp_nanos(dt.unix_timestamp_nanos()) == dtfor every valid DateTime. For example,-1reconstructs1969-12-31T23:59:59.999999999Zexactly.The Rust constructor uses Euclidean division and checked integer conversions, then delegates to the existing seconds/nanoseconds constructor. Out-of-date-range values return
DateError::OutOfRange/ PythonValueError; Python integers outside i128 raiseOverflowError. Existing APIs, pickle reconstruction, dependencies and free-threaded support are unchanged. Includes type stubs, API documentation and executable examples.Regression coverage includes exact epoch and pre-epoch instants, subsecond boundaries, BCE/leap dates, both i32 year endpoints, one nanosecond outside each date limit, i128 extremes and Python input validation. Deterministic samples span the entire supported timestamp interval, with independent differential checks against the
timecrate in its supported range. Before implementation, the existing 200 Python tests passed and the new regression failed because the constructor was absent.Validation on Linux x86_64 (Rust 1.99.1):
cargo test --lockedandcargo test --locked --no-default-features: 24 integration tests + 1 doctest pass each.cargo check --locked --no-default-featuresandcargo fmt --check: pass.cargo clippy --locked --all-targets -- -D warningsand the same with--features python: pass.--pythonpath .venv/bin/python): pass.