types/moment

A Moment is a finite window of time with a start and an end. The helpers here compare a moment with a transaction validity range.

The comparisons ignore the is_inclusive flag of the validity range bounds, and every infinite bound fails the check. That is stricter than stdlib’s interval.includes, interval.is_entirely_after, and interval.is_entirely_before, which honour inclusivity and infinities. Use those when you need exact interval semantics.

Types

A finite moment of time represented as simple start and end integers.

Constructors

  • Moment { start: Int, end: Int }

A finite list of moments of time.

Alias

Moments = List<Moment>

Functions

shift(m: Moment, t: Int) -> Moment

Shifts a moment by some integer amount. This is great for incrementing a fixed moment of time, maybe like an epoch boundary by five days.

moment.shift(this_moment, a_day)

is_logical(m: Moment) -> Bool

Check if a moment data structure is logical: it does not end before it starts and neither end is negative.

moment.is_logical(datum.moment)

is_contained(m: Moment, vr: ValidityRange) -> Bool

Check if a validity range is contained within some moment. This assumes inclusivity.

|start–|lower––upper|–end|

moment.is_contained(datum.moment, this_tx.validity_range)

is_after(m: Moment, vr: ValidityRange) -> Bool

Check if a validity range of a tx is after a moment. This assumes exclusivity.

|start––end|–|lower––upper|

moment.is_after(datum.moment, this_tx.validity_range)

is_before(m: Moment, vr: ValidityRange) -> Bool

Check if a validity range of a tx is before a moment. This assumes exclusivity.

|lower––upper|–|start––end|

moment.is_before(datum.moment, this_tx.validity_range)
Search Document