chrono icon indicating copy to clipboard operation
chrono copied to clipboard

Wrong output from `%Z` specifier when using `Local::now().format()`

Open s1gse9v opened this issue 2 years ago • 1 comments

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

s1gse9v avatar Jul 30 '22 20:07 s1gse9v

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 chronos 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.

esheppa avatar Jul 31 '22 12:07 esheppa

Closing as duplicate of https://github.com/chronotope/chrono/issues/288.

pitdicker avatar Sep 06 '23 16:09 pitdicker