chrono
chrono copied to clipboard
%Z is not supported in parsing but that's unclear in the docs
This works:
DateTime::parse_from_str("2014-09-17 00:00:00 +10:00", "%F %T %z")
But this gives a ParseError(BadFormat):
DateTime::parse_from_str("2014-09-17 00:00:00 AEDT", "%F %T %Z")
This is not a bug, timezone name parsing is documented as unsupported. [1] But I guess the strftime docs should have the duplicate information as well. Thank you for feedback.
[1] In general, many timezone abbreviations are ambiguous enough that relying on %Z is useless. AFAIK glibc recognizes %Z but discards its result; if this is desirable, please file a new issue (I was always reluctant about such legacy behavior, but if there are demands, why not).
Oh right, that makes sense - I forgot that %Z might be useful for formatting (but not parsing). In that case, yeah - a footnote against the "%Z" in https://lifthrasiir.github.io/rust-chrono/chrono/format/strftime/index.html#specifiers would help.
I'm happy to strip off the timezone myself and then parse it in the Local time. As a sanity check, I then compare Local::now().format("%Z") to the timezone I was given. Unfortunately, "%Z" seems to produce a timezone offset (+10:00) just like "%z" does, rather than a timezone name. I guess it only actually returns a name if you use a named timezone (i.e. UTC) rather than Local.
Yes, FixedOffset has a placeholder time zone name. Tzdata support (#23) should give more useful %Z output for Local and others however.
I think parsing time zone abbreviations is something we should support at some point. That some are ambiguous does not mean we can't parse any.
Chrono would need a deeper integration with time zones than it currently has (delegating that to chrono_tz or tz_file). So this won't happen anytime soon...