Implementation of Range and allows easy iteration between Time types.

Provides all power of Iterable features and complements with:

  • Easy way to recover Period
  • Easy way to recover Duration
  • Recover the overlap between TimeRange types
  • Recover the gap between TimeRange types
  • Allows customized way to iterate as navigate between values by UnitOfTime cases
See also Range

no subtypes hierarchy

Initializer
TimeRange(Time from, Time to, UnitOfTime step = ...)
Parameters:
  • from

    The first Element returned by the iterator, if any. This should always produce the same value as iterable.iterator().head. It also represents the caller that created the Range:

    Example: today().to(tomorrow) -> in this case today() is the caller/creator of the range.

  • to

    The limit of the Range where.

    Example:

    Given: today().to(tomorrow) then tomorrow is the to element.

    Given: tomorrow.to(today()) then today() is the to element.

  • step = milliseconds

    Customized way to iterate over each element, it does not interfer in from and to fields, but it does not guarantee that to will be included in iterator.

Attributes
durationSource Codeshared actual Duration duration

Returns the Duration between from and to fields.

Example:

Given: today().to(tomorrow).duration then duration is 86400000 milliseconds.

Given: tomorrow().to(today).duration then duration is -86400000 milliseconds.

fromSource Codeshared actual Time from

The first Element returned by the iterator, if any. This should always produce the same value as iterable.iterator().head. It also represents the caller that created the Range:

Example: today().to(tomorrow) -> in this case today() is the caller/creator of the range.

Refines Range.from
hashSource Codeshared actual Integer hash

This implementation respect the constraint that if x==y then x.hash==y.hash.

Refines Range.hash ultimately refines Object.hash
periodSource Codeshared actual Period period

Returns the Period between from and to fields.

Example:

Given: today().to(tomorrow).duration then duration is 1 day.

Given: tomorrow().to(today).duration then duration is -1 day.

Refines Range.period
stepSource Codeshared actual UnitOfTime step

Customized way to iterate over each element, it does not interfer in from and to fields, but it does not guarantee that to will be included in iterator.

Refines Range.step
toSource Codeshared actual Time to

The limit of the Range where.

Example:

Given: today().to(tomorrow) then tomorrow is the to element.

Given: tomorrow.to(today()) then today() is the to element.

Refines Range.to
Inherited Attributes
Attributes inherited from: Object
Attributes inherited from: Iterable<Element,Absent>
Attributes inherited from: Range<Element,StepBy>
Methods
equalsSource Codeshared actual Boolean equals(Object other)

Returns true if both: this and other are same type and have equal fields from and to.

Refines Range.equals ultimately refines Object.equals
gapSource Codeshared actual TimeRange|[] gap(Range<Time,UnitOfTime> other)

Returns empty or a new Range:

  • Each Range is considered a set then [A..B] is equivalent to [B..A]
  • The precision is based on the lowest unit
  • When the new Range exists it will follow these rules:

Given: [A..B] gap [C..D]

When: AB < CD

[1..2] gap [5..6] = (2,5)

[1..2] gap [6..5] = (2,5)

[2..1] gap [5..6] = (2,5)

[2..1] gap [6..5] = (2,5)

Given: [A..B] gap [C..D]

When: AB > CD

[5..6] gap [1..2] = (2,5)

[5..6] gap [2..1] = (2,5)

[6..5] gap [1..2] = (2,5)

[6..5] gap [2..1] = (2,5)
Refines Range.gap
iteratorSource Codeshared actual Iterator<Time> iterator()

An iterator for the elements belonging to this container. where each jump is based on actual step of this Range.

overlapSource Codeshared actual TimeRange|[] overlap(Range<Time,UnitOfTime> other)

Returns empty or a new Range:

  • Each Range is considered a set then [A..B] is equivalent to [B..A]
  • The precision is based on the lowest unit
  • When the new Range exists it will follow these rules:

Given: [A..B] overlap [C..D]

When: AB < CD

[1..6] overlap [3..9] = [3,6]

[1..6] overlap [9..3] = [3,6]

[6..1] overlap [3..9] = [3,6]

[6..1] overlap [9..3] = [3,6]

Given: [A..B] overlap [C..D]

When: AB > CD

[3..9] overlap [1..6] = [3,6]

[3..9] overlap [6..1] = [3,6]

[9..3] overlap [1..6] = [3,6]

[9..3] overlap [6..1] = [3,6]
stepBySource Codeshared actual TimeRange stepBy(UnitOfTime step)

Define how this Range will get next or previous element while iterating.

Refines Range.stepBy
Inherited Methods
Methods inherited from: Category<Element>
Methods inherited from: Iterable<Element,Absent>
Methods inherited from: Range<Element,StepBy>