chrono icon indicating copy to clipboard operation
chrono copied to clipboard

Parse Zulu suffix with %z?

Open MarcoGorelli opened this issue 2 years ago • 8 comments

The following runs fine:

use chrono::{DateTime};

fn main() {
    let parse_from_str = DateTime::parse_from_str;
    let ts = "2000-01-01T01:23+01:00";
    let fmt = "%Y-%m-%dT%H:%M%z";
    let parsed = parse_from_str(ts, fmt);
    println!("{:?}", parsed);
}

and returns

Ok(2000-01-01T01:23:00+01:00)

However, if I instead put

let ts = "2000-01-01T01:23Z";

then it fails:

Err(ParseError(Invalid))

By contrast, in Python, I can parse that string using this format:

In [1]: import datetime as dt

In [2]: dt.datetime.strptime("2000-01-01T01:23Z", "%Y-%m-%dT%H:%M%z")
Out[2]: datetime.datetime(2000, 1, 1, 1, 23, 0, tzinfo=datetime.timezone.utc)

Should parse_from_str be able to parse the Zulu suffix 'Z' with '%z'?

(note: this question was originally posted on StackOverflow, and it was suggested to report it here)

MarcoGorelli avatar Jan 23 '23 21:01 MarcoGorelli