Type Hierarchy:
Satisfied Interfaces: Category, Iterable<Element,Null>, Range<Date,UnitOfDate>

Implementation of Range and allows easy iteration between Date types.

Provides all power of Iterable features and complements with:

  • Easy way to recover Period
  • Easy way to recover Duration
  • Recover the overlap between DateRange types
  • Recover the gap between DateRange types
  • Allows cutomized way to iterate as navigate between values by UnitOfDate cases
See also: Range
Initializer
DateRange(Date from, Date to, UnitOfDate 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 = days

    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 Code
shared 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.

Refined declaration: duration
fromSource Code
shared actual Date 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.

Refined declaration: from
hashSource Code
shared actual Integer hash

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

Refined declaration: hash
periodSource Code
shared 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.

Refined declaration: period
stepSource Code
shared actual UnitOfDate 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.

Refined declaration: step
toSource Code
shared actual Date 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.

Refined declaration: to
Inherited Attributes
Attributes inherited from: Object
string
Attributes inherited from: Iterable<Element,Absent>
coalesced, cycled, empty, first, indexed, last, rest, sequence, size, string
Attributes inherited from: Range<Element,StepBy>
Methods
equalsSource Code
shared actual Boolean equals(Object other)

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

Refined declaration: equals
gapSource Code
shared actual DateRange|[] gap(Range<Date,UnitOfDate> 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)
Refined declaration: gap
iteratorSource Code
shared actual Iterator<Date> iterator()

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

Refined declaration: iterator
overlapSource Code
shared actual DateRange|[] overlap(Range<Date,UnitOfDate> 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]
Refined declaration: overlap
stepBySource Code
shared actual DateRange stepBy(UnitOfDate step)

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

Refined declaration: stepBy
Inherited Methods
Methods inherited from: Category
contains, containsAny, containsEvery
Methods inherited from: Iterable<Element,Absent>
any, by, chain, collect, count, cycle, defaultNullElements, every, filter, find, findLast, fold, following, iterator, longerThan, map, repeat, select, shorterThan, skipping, skippingWhile, sort, taking, takingWhile
Methods inherited from: Range<Element,StepBy>