Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chrono stftime parsing "%::z" with seconds (+00:00:00) #1629

Open
Fuerst2718 opened this issue Nov 16, 2024 · 1 comment · May be fixed by #1639
Open

chrono stftime parsing "%::z" with seconds (+00:00:00) #1629

Fuerst2718 opened this issue Nov 16, 2024 · 1 comment · May be fixed by #1639

Comments

@Fuerst2718
Copy link

Trying to parse a string with TZ-Information including seconds (+00:00:00) fails (see below 3rd element in the vector).

use chrono::DateTime; // chrono 0.4.38

fn main() {
    // from ...
    // https://docs.rs/chrono/latest/chrono/format/strftime/index.html
    // ... under "TIME ZONE SPECIFIERS:"
    // %::z	| +09:30:00 | Offset from the local time to UTC with seconds.

    let f = "%Y-%m-%dT%H:%M:%S%::z";

    // Testvalues
    let tooshort_ok_toolong = [
        "2023-01-02T23:24:25+01",       // really to short -> fails
        "2023-01-02T23:24:25+01:00",    // although to short but is Ok ?
        "2023-01-02T23:24:25+01:30:01", // _should_ run but fails
    ];

    for s in tooshort_ok_toolong.iter() {
        let t = DateTime::parse_from_str(s, f);
        println!("Parse {:<28} > {} > {:?}", s, f, t);
    }

    let dt = chrono::offset::Utc::now();
    println!("\nFormatting \"{}\" ok > {} > {}",dt, f, dt.format(f));

}

Running the program gives ...

Parse 2023-01-02T23:24:25+01       > %Y-%m-%dT%H:%M:%S%::z > Err(ParseError(TooShort))
Parse 2023-01-02T23:24:25+01:00    > %Y-%m-%dT%H:%M:%S%::z > Ok(2023-01-02T23:24:25+01:00)
Parse 2023-01-02T23:24:25+01:30:01 > %Y-%m-%dT%H:%M:%S%::z > Err(ParseError(TooLong))

Formatting "2024-11-16 18:36:11.833133 UTC" ok > %Y-%m-%dT%H:%M:%S%::z > 2024-11-16T18:36:11+00:00:00

Formatting "2024-11-16 18:20:44.712920200 UTC" ok %Y-%m-%dT%H:%M:%S%::z > 2024-11-16T18:20:44+00:00:00
@djc djc linked a pull request Dec 11, 2024 that will close this issue
@djc
Copy link
Member

djc commented Dec 11, 2024

I've submitted a potential fix as #1639. I'm not sure why this isn't working as expected, seems weird...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants