Skip to main content

precision_time_to_string

Function precision_time_to_string 

Source
fn precision_time_to_string(
    value: i64,
    precision: i32,
) -> Result<String, PrecisionFormatError>
Expand description

Convert a value in precision units since midnight, to a time-of-day string. Errors if value falls outside a single day: NaiveTime + Duration wraps modulo 24 hours, which would otherwise silently misrepresent the value.

The sign check is on value itself, not the chrono::Duration derived from it: at precision 12, duration_from_precision_units truncates towards zero, so a small negative value (e.g. -1) would otherwise round to a zero/non-negative duration and be wrongly accepted.