For now, use the following: (Same for DateTime<Local>
)
fn system_time_to_date_time(t: SystemTime) -> DateTime<UTC> {
let (sec, nsec) = match t.duration_since(UNIX_EPOCH) {
Ok(dur) => (dur.as_secs() as i64, dur.subsec_nanos()),
Err(e) => { // unlikely but should be handled
let dur = e.duration();
let (sec, nsec) = (dur.as_secs() as i64, dur.subsec_nanos());
if nsec == 0 {
(-sec, 0)
} else {
(-sec - 1, 1_000_000_000 - nsec)
}
},
};
UTC.timestamp(sec, nsec)
}
Chrono 0.3 would switch to std::time::SystemTime
and std::time::Duration
for the primary timekeeping, so hopefully this workaround will be gone.