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

Can't parse datetime from another timezone #255

Closed
achntrl opened this issue Jun 20, 2018 · 2 comments
Closed

Can't parse datetime from another timezone #255

achntrl opened this issue Jun 20, 2018 · 2 comments

Comments

@achntrl
Copy link

@achntrl achntrl commented Jun 20, 2018

I noticed that I can't parse a date with another offset than mine.

I'm in the +0200 timezone:

extern crate chrono;

use chrono::{Local, TimeZone};

fn main() {
    let working_input_string = "05/Jun/2018:20:55:45 +0200";
    match Local.datetime_from_str(working_input_string,"%d/%b/%Y:%T %z") {
        Ok(d) => println!("{:?}", d),  
        Err(err) => println!("{}", err),
    }  // This will Ok and print the date: 2018-06-05T20:55:45+02:00

    let failing_input_string = "05/Jun/2018:20:55:45 +0300";
    match Local.datetime_from_str(failing_input_string,"%d/%b/%Y:%T %z") {
        Ok(d) => println!("{:?}", d),
        Err(err) => println!("{}", err), 
    }  // This will Err and print "no possible date and time matching input"
}

I would have expected failing_input_string to be parsed as 2018-06-05T19:55:45+02:00. Is that something that we shouldn't do or is this a missing feature / a bug ?

There is the same issue with Utc: in that case I can parse "05/Jun/2018:20:55:45 +0000" but not any other offset

@achntrl achntrl changed the title Can't parse from another timezone Can't parse datetime from another timezone Jun 20, 2018
@svenfoo
Copy link

@svenfoo svenfoo commented Feb 13, 2020

As far as I understand that's intentional. You can use DateTime::parse_from_str() instead to be able to parse a date with timezone specifier from any timezone.

@quodlibetor
Copy link
Contributor

@quodlibetor quodlibetor commented Jul 11, 2020

svenfoo is correct.

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

Successfully merging a pull request may close this issue.

None yet
3 participants