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

Unable to parse millisecond unix timestamps #560

Open
jszwedko opened this issue May 6, 2021 · 3 comments
Open

Unable to parse millisecond unix timestamps #560

jszwedko opened this issue May 6, 2021 · 3 comments
Labels

Comments

@jszwedko
Copy link

jszwedko commented May 6, 2021

Hey all,

I might be missing something, but I'm not seeing a way to use parse_from_str with unix timestamps that include milliseconds.

I would have expected something like:

fn main() {
    use chrono::TimeZone;
    let dt = chrono::offset::Utc.datetime_from_str("1620309579123", "%s%3f");
    println!("{:?}", dt);
}

to work, but it gives:

Err(ParseError(TooShort))

Is this possible or could it be added? I could try taking a shot at a PR.

@jgoday
Copy link

jgoday commented May 14, 2021

@jszwedko Seems that Timestmap in fn parse_internal (format/parse.rs), try to consume all digits without taking into account next items/formats. I have changed it to allow for the next fixed item length, in case there is no separator between them (Nanosecond3NotDot in this case).

let dt = chrono::offset::Utc.datetime_from_str("1620309579123", "%s%3f");

should return now

Ok(2021-05-06T13:59:39.123)

Can make a PR if this is a valid approach
(jgoday@c44fd78).

@jszwedko
Copy link
Author

Nice, thanks @jgoday ! That seems like a reasonable approach to me.

@yalinglee
Copy link

Hi! Would it be possible to include this fix in the next release? Thanks!

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

No branches or pull requests

4 participants