    import {Interval} from 'luxon/src/interval.js'

public class | source

# Interval

An Interval object represents a half-open interval of time, where each endpoint is a DateTime. Conceptually, it's a container for those two endpoints, accompanied by methods for creating, parsing, interrogating, comparing, transforming, and formatting them.

Here is a brief overview of the most commonly used methods and getters in Interval:

- Creation To create an Interval, use fromDateTimes, after, before, or fromISO.
- Accessors Use start and end to get the start and end.
- Interogation To analyze the Interval, use count, length, hasSame, contains, isAfter, or isBefore.
- Transformation To create other Intervals out of this one, use set, splitAt, splitBy, divideEqually, merge, xor, union, intersection, or difference.
- Comparison To compare this Interval to another one, use equals, overlaps, abutsStart, abutsEnd, engulfs
- Output* To convert the Interval into other representations, see toString, toISO, toFormat, and toDuration.

## Static Method Summary

Static Public Methods
public static | after(start: DateTime | object | Date, duration: Duration | number | object): Interval Create an Interval from a start DateTime and a Duration to extend to. |
public static | before(end: DateTime | object | Date, duration: Duration | number | object): Interval Create an Interval from an end DateTime and a Duration to extend backwards to. |
public static | fromDateTimes(start: DateTime | object | Date, end: DateTime | object | Date): Interval Create an Interval from a start DateTime and an end DateTime. |
public static | fromISO(string: string, opts: object): Interval Create an Interval from an ISO 8601 string |
public static | invalid(reason: *): Interval Create an invalid Interval. |
public static | merge(intervals: [Interval]): [Interval] Merge an array of Intervals into a equivalent minimal set of Intervals. |
public static | xor(intervals: [Interval]): [Interval] Return an array of Intervals representing the spans of time that only appear in one of the specified Intervals. |

## Member Summary

Public Members
public get | end: DateTime: * Returns the end of the Interval |
public get | invalidReason: string: * Returns an explanation of why this Interval became invalid, or null if the Interval is valid |
public get | isValid: boolean: * Returns whether this Interval's end is at least its start, i.e. that the Interval isn't 'backwards'. |
public get | start: DateTime: * Returns the start of the Interval |

## Method Summary

Public Methods
public | abutsEnd(other: Interval): boolean Return whether this Interval's start is adjacent to the specified Interval's end. |
public | abutsStart(other: Interval): boolean Return whether this Interval's end is adjacent to the specified Interval's start. |
public | contains(dateTime: DateTime): boolean Return this Interval contains the specified DateTime. |
public | count(unit: string): number Returns the count of minutes, hours, days, months, or years included in the Interval, even in part. |
public | difference(intervals: ...Interval): Interval Return an Interval representing the span of time in this Interval that doesn't overlap with any of the specified Intervals. |
public | divideEqually(numberOfParts: number): [Interval] Split this Interval into the specified number of smaller intervals. |
public | engulfs(other: Interval): boolean Return whether this Interval engulfs the start and end of the specified Interval. |
public | equals(other: Interval): boolean Return whether this Interval has the same start and end as the specified Interval. |
public | hasSame(unit: string): boolean Returns whether this Interval's start and end are both in the same unit of time |
public | intersection(other: Interval): Interval Return an Interval representing the intersection of this Interval and the specified Interval. |
public | isAfter(dateTime: DateTime): boolean Return this Interval's start is after the specified DateTime. |
public | isBefore(dateTime: Datetime): boolean Return this Interval's end is before the specified DateTime. |
public | isEmpty(): boolean Return whether this Interval has the same start and end DateTimes. |
public | length(unit: string): number Returns the length of the Interval in the specified unit. |
public | overlaps(other: Interval): boolean Return whether this Interval overlaps with the specified Interval |
public | set(values: object): Interval "Sets" the start and/or end dates. |
public | splitAt(dateTimes: ...DateTimes): [Interval] Split this Interval at each of the specified DateTimes |
public | splitBy(duration: Duration | number | object): [Interval] Split this Interval into smaller Intervals, each of the specified length. |
public | toDuration(units: ...string): Duration Return a Duration representing the time spanned by this interval. |
public | toFormat(dateFormat: string, opts: object): string Returns a string representation of this Interval formatted according to the specified format string. |
public | toISO(opts: object): string Returns an ISO 8601-compliant string representation of this Interval. |
public | toString(): string Returns a string representation of this Interval appropriate for debugging. |
public | union(other: Interval): Interval Return an Interval representing the union of this Interval and the specified Interval. |

## Static Public Methods

### public static after(start: DateTime | object | Date, duration: Duration | number | object): Interval source

Create an Interval from a start DateTime and a Duration to extend to.

#### Params:

Name | Type | Attribute | Description
start | DateTime | object | Date |  |
duration | Duration | number | object |  | the length of the Interval.

#### Return:

Interval

### public static before(end: DateTime | object | Date, duration: Duration | number | object): Interval source

Create an Interval from an end DateTime and a Duration to extend backwards to.

#### Params:

Name | Type | Attribute | Description
end | DateTime | object | Date |  |
duration | Duration | number | object |  | the length of the Interval.

#### Return:

Interval

### public static fromDateTimes(start: DateTime | object | Date, end: DateTime | object | Date): Interval source

Create an Interval from a start DateTime and an end DateTime. Inclusive of the start but not the end.

#### Params:

Name | Type | Attribute | Description
start | DateTime | object | Date |  |
end | DateTime | object | Date |  |

#### Return:

Interval

### public static fromISO(string: string, opts: object): Interval source

Create an Interval from an ISO 8601 string

#### Params:

Name | Type | Attribute | Description
string | string |  | the ISO string to parse
opts | object |  | options to pass {@see DateTime.fromISO}

#### Return:

Interval

### public static invalid(reason: *): Interval source

Create an invalid Interval.

#### Params:

Name | Type | Attribute | Description
reason | * |  |

#### Return:

Interval

### public static merge(intervals: [Interval]): [Interval] source

Merge an array of Intervals into a equivalent minimal set of Intervals. Combines overlapping and adjacent Intervals.

#### Params:

Name | Type | Attribute | Description
intervals | [Interval] |  |

#### Return:

[Interval]

### public static xor(intervals: [Interval]): [Interval] source

Return an array of Intervals representing the spans of time that only appear in one of the specified Intervals.

#### Params:

Name | Type | Attribute | Description
intervals | [Interval] |  |

#### Return:

[Interval]

## Public Members

### public get end: DateTime: * source

Returns the end of the Interval

#### Return:

DateTime

### public get invalidReason: string: * source

Returns an explanation of why this Interval became invalid, or null if the Interval is valid

#### Return:

string

### public get isValid: boolean: * source

Returns whether this Interval's end is at least its start, i.e. that the Interval isn't 'backwards'.

#### Return:

boolean

### public get start: DateTime: * source

Returns the start of the Interval

#### Return:

DateTime

## Public Methods

### public abutsEnd(other: Interval): boolean source

Return whether this Interval's start is adjacent to the specified Interval's end.

#### Params:

Name | Type | Attribute | Description
other | Interval |  |

#### Return:

boolean

### public abutsStart(other: Interval): boolean source

Return whether this Interval's end is adjacent to the specified Interval's start.

#### Params:

Name | Type | Attribute | Description
other | Interval |  |

#### Return:

boolean

### public contains(dateTime: DateTime): boolean source

Return this Interval contains the specified DateTime.

#### Params:

Name | Type | Attribute | Description
dateTime | DateTime |  |

#### Return:

boolean

### public count(unit: string): number source

Returns the count of minutes, hours, days, months, or years included in the Interval, even in part. Unlike length this counts sections of the calendar, not periods of time, e.g. specifying 'day' asks 'what dates are included in this interval?', not 'how many days long is this interval?'

#### Params:

Name | Type | Attribute | Description
unit | string | optional default: 'milliseconds' | the unit of time to count.

#### Return:

number

### public difference(intervals: ...Interval): Interval source

Return an Interval representing the span of time in this Interval that doesn't overlap with any of the specified Intervals.

#### Params:

Name | Type | Attribute | Description
intervals | ...Interval |  |

#### Return:

Interval

### public divideEqually(numberOfParts: number): [Interval] source

Split this Interval into the specified number of smaller intervals.

#### Params:

Name | Type | Attribute | Description
numberOfParts | number |  | The number of Intervals to divide the Interval into.

#### Return:

[Interval]

### public engulfs(other: Interval): boolean source

Return whether this Interval engulfs the start and end of the specified Interval.

#### Params:

Name | Type | Attribute | Description
other | Interval |  |

#### Return:

boolean

### public equals(other: Interval): boolean source

Return whether this Interval has the same start and end as the specified Interval.

#### Params:

Name | Type | Attribute | Description
other | Interval |  |

#### Return:

boolean

### public hasSame(unit: string): boolean source

Returns whether this Interval's start and end are both in the same unit of time

#### Params:

Name | Type | Attribute | Description
unit | string |  | the unit of time to check sameness on

#### Return:

boolean

### public intersection(other: Interval): Interval source

Return an Interval representing the intersection of this Interval and the specified Interval. Specifically, the resulting Interval has the maximum start time and the minimum end time of the two Intervals.

#### Params:

Name | Type | Attribute | Description
other | Interval |  |

#### Return:

Interval

### public isAfter(dateTime: DateTime): boolean source

Return this Interval's start is after the specified DateTime.

#### Params:

Name | Type | Attribute | Description
dateTime | DateTime |  |

#### Return:

boolean

### public isBefore(dateTime: Datetime): boolean source

Return this Interval's end is before the specified DateTime.

#### Params:

Name | Type | Attribute | Description
dateTime | Datetime |  |

#### Return:

boolean

### public isEmpty(): boolean source

Return whether this Interval has the same start and end DateTimes.

#### Return:

boolean

### public length(unit: string): number source

Returns the length of the Interval in the specified unit.

#### Params:

Name | Type | Attribute | Description
unit | string |  | the unit (such as 'hours' or 'days') to return the length in.

#### Return:

number

### public overlaps(other: Interval): boolean source

Return whether this Interval overlaps with the specified Interval

#### Params:

Name | Type | Attribute | Description
other | Interval |  |

#### Return:

boolean

### public set(values: object): Interval source

"Sets" the start and/or end dates. Returns a newly-constructed Interval.

#### Params:

Name | Type | Attribute | Description
values | object |  | the values to set
values.start | DateTime |  | the starting DateTime
values.end | DateTime |  | the ending DateTime

#### Return:

Interval

### public splitAt(dateTimes: ...DateTimes): [Interval] source

Split this Interval at each of the specified DateTimes

#### Params:

Name | Type | Attribute | Description
dateTimes | ...DateTimes |  | the unit of time to count.

#### Return:

[Interval]

### public splitBy(duration: Duration | number | object): [Interval] source

Split this Interval into smaller Intervals, each of the specified length. Left over time is grouped into a smaller interval

#### Params:

Name | Type | Attribute | Description
duration | Duration | number | object |  | The length of each resulting interval.

#### Return:

[Interval]

### public toDuration(units: ...string): Duration source

Return a Duration representing the time spanned by this interval.

#### Params:

Name | Type | Attribute | Description
units | ...string | optional default: ['milliseconds'] | the units (such as 'hours' or 'days') to include in the duration.

#### Return:

Duration

#### Example:

    Interval.fromDateTimes(dt1, dt2).toDuration().toObject() //=> { milliseconds: 88489257 }

    Interval.fromDateTimes(dt1, dt2).toDuration('days').toObject() //=> { days: 1.0241812152777778 }

    Interval.fromDateTimes(dt1, dt2).toDuration('hours', 'minutes').toObject() //=> { hours: 24, minutes: 34.82095 }

    Interval.fromDateTimes(dt1, dt2).toDuration('hours', 'minutes', 'seconds').toObject() //=> { hours: 24, minutes: 34, seconds: 49.257 }

    Interval.fromDateTimes(dt1, dt2).toDuration('seconds').toObject() //=> { seconds: 88489.257 }

### public toFormat(dateFormat: string, opts: object): string source

Returns a string representation of this Interval formatted according to the specified format string.

#### Params:

Name | Type | Attribute | Description
dateFormat | string |  | the format string. This string formats the start and end time. See DateTime.toFormat for details.
opts | object |  | options
opts.separator | string | optional default: ' – ' | a separator to place between the start and end representations

#### Return:

string

### public toISO(opts: object): string source

Returns an ISO 8601-compliant string representation of this Interval.

#### Params:

Name | Type | Attribute | Description
opts | object |  | The same options as DateTime.toISO

#### Return:

string

#### See:

- https://en.wikipedia.org/wiki/ISO_8601#Time_intervals

### public toString(): string source

Returns a string representation of this Interval appropriate for debugging.

#### Return:

string

### public union(other: Interval): Interval source

Return an Interval representing the union of this Interval and the specified Interval. Specifically, the resulting Interval has the minimum start time and the maximum end time of the two Intervals.

#### Params:

Name | Type | Attribute | Description
other | Interval |  |

#### Return:

Interval