Skip to content

Parse Zulu suffix with %z? #945

@MarcoGorelli

Description

@MarcoGorelli

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions