struct Nudge {
span: Span,
rounded_relative_end: ri128<{ i128::MIN }, { i128::MAX }>,
grew_big_unit: bool,
}
Expand description
The result of a span rounding strategy. There are three:
- Rounding spans relative to civil datetimes using only invariant units (days or less). This is achieved by converting the span to a simple integer number of nanoseconds and then rounding that.
- Rounding spans relative to either a civil datetime or a zoned datetime where rounding might involve changing non-uniform units. That is, when the smallest unit is greater than days for civil datetimes and greater than hours for zoned datetimes.
- Rounding spans relative to a zoned datetime whose smallest unit is less than days.
Each of these might produce a bottom heavy span that needs to be re-balanced. This type represents that result via one of three constructors corresponding to each of the above strategies, and then provides a routine for rebalancing via “bubbling.”
Fields§
§span: Span
A possibly bottom heavy rounded span.
rounded_relative_end: ri128<{ i128::MIN }, { i128::MAX }>
The nanosecond timestamp corresponding to relative + span
, where
span
is the (possibly bottom heavy) rounded span.
grew_big_unit: bool
Whether rounding may have created a bottom heavy span such that a calendar unit might need to be incremented after re-balancing smaller units.
Implementations§
Source§impl Nudge
impl Nudge
Sourcefn relative_invariant(
balanced: Span,
relative_end: ri128<{ i128::MIN }, { i128::MAX }>,
smallest: Unit,
largest: Unit,
increment: ri128<{ i128::MIN }, { i128::MAX }>,
mode: RoundMode,
) -> Result<Nudge, Error>
fn relative_invariant( balanced: Span, relative_end: ri128<{ i128::MIN }, { i128::MAX }>, smallest: Unit, largest: Unit, increment: ri128<{ i128::MIN }, { i128::MAX }>, mode: RoundMode, ) -> Result<Nudge, Error>
Performs rounding on the given span limited to invariant units.
For civil datetimes, this means the smallest unit must be days or less, but the largest unit can be bigger. For zoned datetimes, this means that both the largest and smallest unit must be hours or less. This is because zoned datetimes with rounding that can spill up to days requires special handling.
It works by converting the span to a single integer number of nanoseconds, rounding it and then converting back to a span.
Sourcefn relative_calendar(
balanced: Span,
relative_start: &Relative<'_>,
relative_end: &Relative<'_>,
smallest: Unit,
increment: ri128<{ i128::MIN }, { i128::MAX }>,
mode: RoundMode,
) -> Result<Nudge, Error>
fn relative_calendar( balanced: Span, relative_start: &Relative<'_>, relative_end: &Relative<'_>, smallest: Unit, increment: ri128<{ i128::MIN }, { i128::MAX }>, mode: RoundMode, ) -> Result<Nudge, Error>
Performs rounding on the given span where the smallest unit configured implies that rounding will cover calendar or “non-uniform” units. (That is, units whose length can change based on the relative datetime.)
Sourcefn relative_zoned_time(
balanced: Span,
relative_start: &RelativeZoned<'_>,
smallest: Unit,
increment: ri128<{ i128::MIN }, { i128::MAX }>,
mode: RoundMode,
) -> Result<Nudge, Error>
fn relative_zoned_time( balanced: Span, relative_start: &RelativeZoned<'_>, smallest: Unit, increment: ri128<{ i128::MIN }, { i128::MAX }>, mode: RoundMode, ) -> Result<Nudge, Error>
Performs rounding on the given span where the smallest unit is hours or less and the relative datetime is time zone aware.
Sourcefn bubble(
&self,
relative: &RelativeSpan<'_>,
smallest: Unit,
largest: Unit,
) -> Result<Span, Error>
fn bubble( &self, relative: &RelativeSpan<'_>, smallest: Unit, largest: Unit, ) -> Result<Span, Error>
This “bubbles” up the units in a potentially “bottom heavy” span to larger units. For example, P1m50d relative to March 1 is bottom heavy. This routine will bubble the days up to months to get P2m19d.
§Errors
This routine fails if any arithmetic on the individual units fails, or when span arithmetic on the relative datetime given fails.