-
Notifications
You must be signed in to change notification settings - Fork 545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Utc nanoseconds do not always roundtrip #1289
Comments
@crepererum Excellent issue report. As far as I can tell in this code the first pub fn timestamp_nanos(&self) -> i64 {
self.timestamp()
.checked_mul(1_000_000_000)
.and_then(|ns| ns.checked_add(i64::from(self.timestamp_subsec_nanos())))
.expect("value can not be represented in a timestamp with nanosecond precision.")
} For negative timestamps we should instead add @crepererum Interested in making a PR? |
crepererum
added a commit
to crepererum/chrono
that referenced
this issue
Sep 15, 2023
crepererum
added a commit
to crepererum/chrono
that referenced
this issue
Sep 15, 2023
crepererum
added a commit
to crepererum/chrono
that referenced
this issue
Sep 15, 2023
pitdicker
pushed a commit
that referenced
this issue
Sep 15, 2023
pitdicker
pushed a commit
to pitdicker/chrono
that referenced
this issue
Sep 16, 2023
3 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reproducer
Code
Expected Result
Test passes.
Actual Result
Test panics when calling
dt.timestamp_nanos()
(so we don't even get to the actual comparison:value can not be represented in a timestamp with nanosecond precision.
Technical Background
dt.timestamp()
is-9223372037
, howevernanos / 1_000_000_000
is-9223372036
, hence I conclude that this IF branch was taken:chrono/src/offset/mod.rs
Lines 427 to 430 in b64cedc
Hence this
checked_mul
overflows:chrono/src/naive/datetime/mod.rs
Line 482 in b64cedc
My guess is that the conversion routine (first code block) isn't entirely accurate.The conversion is alright, I rather think when converting back we have to be more careful.The text was updated successfully, but these errors were encountered: