jiff::fmt::util

Function fractional_time_to_duration

Source
pub(crate) fn fractional_time_to_duration(
    unit: Unit,
    fraction: ri32<0, { _ }>,
) -> Result<SignedDuration, Error>
Expand description

Like fractional_time_to_span, but just converts the fraction of the given unit to a signed duration.

Since a signed duration doesn’t keep track of individual units, there is no loss of fidelity between it and ISO 8601 durations like there is for Span.

Note that fraction can be a fractional hour, minute, second, millisecond or microsecond (even though its type suggests its only a fraction of a second). When milliseconds or microseconds, the given fraction has any sub-nanosecond precision truncated.

§Errors

This returns an error if unit is not Hour, Minute, Second, Millisecond or Microsecond.