jiff::span

Function round_span_invariant

Source
fn round_span_invariant(
    span: Span,
    smallest: Unit,
    largest: Unit,
    increment: ri128<{ i128::MIN }, { i128::MAX }>,
    mode: RoundMode,
) -> Result<Span, Error>
Expand description

Rounds a span consisting of only invariant units.

This only applies when the max of the units in the span being rounded, the largest configured unit and the smallest configured unit are all invariant. That is, days or lower for spans without a relative datetime or a relative civil datetime, and hours or lower for spans with a relative zoned datetime.

All we do here is convert the span to an integer number of nanoseconds, round that and then convert back. There aren’t any tricky corner cases to consider here.