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

NaiveDateTime::from_millis #430

Closed
GopherJ opened this issue Jun 1, 2020 · 4 comments
Closed

NaiveDateTime::from_millis #430

GopherJ opened this issue Jun 1, 2020 · 4 comments

Comments

@GopherJ
Copy link

GopherJ commented Jun 1, 2020

No description provided.

@GopherJ
Copy link
Author

GopherJ commented Jun 1, 2020

This method is missing

@GopherJ GopherJ changed the title NaiveDateTime::from_timestamp_millis NaiveDateTime::from_millis Jun 1, 2020
@GopherJ
Copy link
Author

GopherJ commented Jun 1, 2020

It's super ugly to do:

   NaiveDateTime::from_timestamp(
          (timestamp / 1000) as i64,
          0,
   )

@Pscheidl
Copy link
Contributor

It's super ugly to do:

   NaiveDateTime::from_timestamp(
          (timestamp / 1000) as i64,
          0,
   )

Doing this results in reduced precision, as millis from the last second are lost. Do this instead (then it gets even more verbose).

        let secs = millis / 1000;
        let nsecs = (millis % 1000) as u32 * 1_000_000;
        NaiveDateTime::from_timestamp_opt(secs, nsecs)

@pitdicker
Copy link
Collaborator

Fixed in #818, backported to 0.4.x in #823.

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

No branches or pull requests

3 participants