chrono icon indicating copy to clipboard operation
chrono copied to clipboard

[Bug] Parsing an string with %Z causes the library to panic

Open DiegoMagdaleno opened this issue 3 years ago • 1 comments

I have the following Date string:

"2020-04-12 22:10 ACST"

And I do the following:

let datetime = chrono::DateTime::parse_from_str(date_str, "%Y-%m-%d %H:%M %Z").unwrap();

And I get a panic:

   Compiling playground v0.0.1 (/playground)
    Finished dev [unoptimized + debuginfo] target(s) in 1.67s
     Running `target/debug/playground`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ParseError(NotEnough)', src/main.rs:5:80
stack backtrace:
   0: rust_begin_unwind
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:517:5
   1: core::panicking::panic_fmt
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/panicking.rs:101:14
   2: core::result::unwrap_failed
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/result.rs:1617:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/result.rs:1299:23
   4: playground::main
             at ./src/main.rs:5:16
   5: core::ops::function::FnOnce::call_once
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace

This doesn't happen in C with strftime()

Playground link: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=bc851bfde4ae1f6e76de8d52e3934bdc

DiegoMagdaleno avatar Nov 15 '21 18:11 DiegoMagdaleno

Confirm, I run into the same issue.

PumpkinSeed avatar Dec 29 '21 19:12 PumpkinSeed

I reopened the related issue https://github.com/chronotope/chrono/issues/38 because it is older and has some useful discussion. Closing this one as a duplicate.

pitdicker avatar Jul 21 '23 10:07 pitdicker