chrono
chrono copied to clipboard
Wrong output from `%Z` specifier when using `Local::now().format()`
See below for an example:
use chrono::Local;
fn main() {
println!("{}",Local::now().format("%z"));
println!("{}",Local::now().format("%Z"));
}
Output:
+0200
+02:00
Expected output:
+0200
CEST
Interestingly, everything works fine when you substitute Local
for Utc
Thanks for reporting this @s1gse9v. We don't currently guarantee identical behavior to the date
command, however we do use it as a guide (for example in testing the functionality of Local
), but this is a difference that I hadn't realized until now and it would be nice to match the output if we can.
This should be relatively straightforward on Linux, and a little bit more involved on Windows, however it looks like your use case would need this to be properly cross platform so I'll aim for both.
Unfortunately I think the changes needed to make here would result in a change of chrono
s public API as currently Local
uses FixedOffset
and that would need to be changed for a new data type that stores the name of the timezone internally. This means that if/when this was fixed, it would be only in a 0.5
release. Alternatively we could store this as an optional field in FixedOffset
but that may have unintended performance implications.
Closing as duplicate of https://github.com/chronotope/chrono/issues/288.