Supports microsecond precision, but doesn't support nanoseconds
Closed this issue · 3 comments
bobhy commented
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()
.
bspeice commented
Took a quick look, I think the change would need to fix two things:
- Micros are currently
i32
, needs to bei64
to support the full range Parser::parsems
explicitly slices 6 characters from the text, needs to allow 9
Should be able to implement that in the near future.
bspeice commented
Bit delayed on it, but I was correct that it was a fairly simple change. Nanoseconds now supported, and released as 1.4.0. Let me know if you need anything else!
bobhy commented
Thanks, now I just have to get the team to update the cargo lock...
…On Sat, Mar 25, 2023, 9:33 AM bspeice ***@***.***> wrote:
Bit delayed on it, but I was correct that it was a fairly simple change.
Nanoseconds now supported, and released as 1.4.0. Let me know if you need
anything else!
—
Reply to this email directly, view it on GitHub
<#40 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAPBIZE5SHWI34PUFYJQN63W5ZKNZANCNFSM6AAAAAAVOG5FRE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>