Skip to content

Supports microsecond precision, but doesn't support nanoseconds #40

@bobhy

Description

@bobhy

Not a bug report, it's a feature request.

Crate chrono supports datetime with nanosecond precision, but dtparse appears to support "only" microseconds. We use dtparse in nushell, but it's silently truncating user input.

use chrono::prelude::*;
use dtparse::parse;

fn main() {
    assert_eq!(
        parse("2008.12.29T08:09:10.123456789").unwrap(),
        (
            NaiveDate::from_ymd_opt(2008, 12, 29)
                .unwrap()
                .and_hms_nano_opt(8, 9, 10, 123_456_789)
                .unwrap(),
            None
        )
    );
}

produces:

Compiling work v0.1.0 (/home/bobhy/src/rust/work)
    Finished dev [unoptimized + debuginfo] target(s) in 0.50s
     Running `target/debug/work`
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `(2008-12-29T08:09:10.123456, None)`,
 right: `(2008-12-29T08:09:10.123456789, None)`', src/main.rs:5:5
stack backtrace:
   0: rust_begin_unwind
             at /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/core/src/panicking.rs:65:14
--- clip ---

Note dtparse simply truncated the sub-microsecond nanosecond bits that were specified in the call to dtparse().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions