Open behnam-oneschema opened 3 months ago
You have a time zone specifier (%z
) combined with a type (NaiveDateTime
) that does not support time zones -- I think this is the problem. Unfortunately the format()
method was not defined as fallible, so we don't have a good way of yielding an error -- although maybe we should deprecate format()
in favor of try_format()
in 0.4?
We have been working on making this better on the 0.5 branch, including hopefully making this sort of thing fail to compile.
I see. My assumption was that if a formatting option is not supported, either DelayedFormat
won't be instantiated, or the formatting option would be ignored (becoming a literal string).
Yeah, I would love to see a fallible API for this! Thanks!
Now that you mentioned the behavior, I understand the intention of the last paragraph of the doc: https://docs.rs/chrono/latest/chrono/naive/struct.NaiveDateTime.html#method.format . I think it might be useful to make these docs more explicit about the "fails" being a thread panic, either by updating the wording of the sentence, or maybe even adding a "Panics" section to the doc similar to the rust-lang docs (example)
Anyways, leaving it for you to decide if any it's useful to keep this issue open. Thanks again for the prompt response!
I think it might be useful to make these docs more explicit about the "fails" being a thread panic, either by updating the wording of the sentence, or maybe even adding a "Panics" section to the doc similar to the rust-lang docs (example)
Would you be able to make a PR with a proposal? Would be much appreciated!
Okay, submitted https://github.com/chronotope/chrono/pull/1590
Unfortunately the
format()
method was not defined as fallible, so we don't have a good way of yielding an error -- although maybe we should deprecateformat()
in favor oftry_format()
in 0.4?
It would be amazing if a failable try_format
API were made available.
Especially when chrono is used in other libraries (like polars in our case) it is quite annoying to get an unexpected panic in third party code. While this was a configuration error on our part, it was not easy to figure out what went wrong, as Rust does not provide an appropriate panic message either.
This code:
Results in these debug outputs:
which seem to be all valid.
Then panics when trying to render the formatting to string:
I can repro this on both default features, as well as
{ version = "0.4.38", default-features = false, features = ["std"] }
.