Skip to main content

round_to_micros

Function round_to_micros 

Source
fn round_to_micros(ts: NaiveDateTime) -> (NaiveDateTime, u32)
Expand description

Rounds ts to microseconds, returning the value whose date and seconds are to be rendered plus the fraction to append to it.

A fraction that rounds up to a full second is carried into the seconds field rather than written as a fractional 1_000_000 microseconds, which the trailing-zero stripper would turn into a nonsense .1, roughly one second early. At the very end of chrono’s range the carry has nowhere to go, so the fraction saturates at .999999 rather than the value rolling over to an unrepresentable date.