chrono icon indicating copy to clipboard operation
chrono copied to clipboard

NaiveDateTime::from_millis

Open 0x8f701 opened this issue 5 years ago • 3 comments

0x8f701 avatar Jun 01 '20 18:06 0x8f701

This method is missing

0x8f701 avatar Jun 01 '20 18:06 0x8f701

It's super ugly to do:

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

0x8f701 avatar Jun 01 '20 19:06 0x8f701

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)

Pscheidl avatar Sep 11 '22 19:09 Pscheidl

Fixed in https://github.com/chronotope/chrono/pull/818, backported to 0.4.x in https://github.com/chronotope/chrono/pull/823.

pitdicker avatar Jun 07 '23 14:06 pitdicker