chrono
chrono copied to clipboard
NaiveDateTime::from_millis
This method is missing
It's super ugly to do:
NaiveDateTime::from_timestamp(
(timestamp / 1000) as i64,
0,
)
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)
Fixed in https://github.com/chronotope/chrono/pull/818, backported to 0.4.x in https://github.com/chronotope/chrono/pull/823.