Skip to content

ISO 8601 parsing from string sometimes is off by 1 nanosecond #488

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

Closed
mati865 opened this issue Jul 22, 2022 · 0 comments · Fixed by #489
Closed

ISO 8601 parsing from string sometimes is off by 1 nanosecond #488

mati865 opened this issue Jul 22, 2022 · 0 comments · Fixed by #489
Labels
A-parsing Area: parsing A-well-known-format-description Area: well known format descriptions C-bug Category: bug in current code

Comments

@mati865
Copy link
Contributor

mati865 commented Jul 22, 2022

Sometimes timestamps parsed from string are off by 1 nanosecond from the string text:

use time::{format_description::well_known::iso8601::Iso8601, macros::datetime, OffsetDateTime};

fn main() {
    let timestamp = "2022-07-22T12:52:50.349409+00:00";
    let parsed = OffsetDateTime::parse(timestamp, &Iso8601::DEFAULT).unwrap();
    // panic: `left` is `nanosecond: 349408999`, `right` is `nanosecond: 349409000`
    assert_eq!(parsed, datetime!(2022-07-22 12:52:50.349409000 UTC));
}

Better reproducer: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=31030fbca526a129ba26e1528bbe163a

mati865 added a commit to mati865/time that referenced this issue Jul 22, 2022
mati865 added a commit to mati865/time that referenced this issue Jul 22, 2022
@jhpratt jhpratt added C-bug Category: bug in current code A-parsing Area: parsing A-well-known-format-description Area: well known format descriptions labels Jul 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parsing Area: parsing A-well-known-format-description Area: well known format descriptions C-bug Category: bug in current code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants