Skip to content
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

DelayedFormat panics on to_string() #956

Open
korest opened this issue Feb 3, 2023 · 1 comment
Open

DelayedFormat panics on to_string() #956

korest opened this issue Feb 3, 2023 · 1 comment

Comments

@korest
Copy link

korest commented Feb 3, 2023

I'm trying to format a DateTime with a pattern (possibly invalid 2f for millis, 3f and 6f work), however it panics on to_string:

fn main() {
   let dt = chrono::Local::now();
   let formatted = dt.format("%H:%M:%S%.2f");
   println!("{}", formatted.to_string());
}

result of a cargo run:

rust_test % cargo run 
    Finished dev [unoptimized + debuginfo] target(s) in 0.10s
     Running `target/debug/rust_test`
thread 'main' panicked at 'a Display implementation returned an error unexpectedly: Error', /rustc/574b64a97f52162f965bc201e47f0af8279ca65d/library/alloc/src/string.rs:2537:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

cargo 1.68.0-nightly (2381cbdb4 2022-12-23)
chrono v0.4.23

@djc
Copy link
Member

djc commented Feb 3, 2023

Yeah, only 3, 6, 9 or f may follow a %. in a format string, so it panics. See #902 for a more robust error handling strategy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants