# TimeIntervalCollection

#### new Cesium.TimeIntervalCollection(intervals)
engine/Source/Core/TimeIntervalCollection.js 23

A non-overlapping collection of `TimeInterval` instances sorted by start time.

Name | Type | Description
--- | --- | ---
`intervals` | Array.<TimeInterval> | optional An array of intervals to add to the collection.

### Members

#### readonly changedEvent : Event
engine/Source/Core/TimeIntervalCollection.js 42

Gets an event that is raised whenever the collection of intervals change.

#### readonly isEmpty : boolean
engine/Source/Core/TimeIntervalCollection.js 120

Gets whether or not the collection is empty.

#### readonly isStartIncluded : boolean
engine/Source/Core/TimeIntervalCollection.js 67

Gets whether or not the start time is included in the collection.

#### readonly isStopIncluded : boolean
engine/Source/Core/TimeIntervalCollection.js 94

Gets whether or not the stop time is included in the collection.

#### readonly length : number
engine/Source/Core/TimeIntervalCollection.js 108

Gets the number of intervals in the collection.

#### readonly start : JulianDate
engine/Source/Core/TimeIntervalCollection.js 54

Gets the start time of the collection.

#### readonly stop : JulianDate
engine/Source/Core/TimeIntervalCollection.js 80

Gets the stop time of the collection.

### Methods

#### static Cesium.TimeIntervalCollection.fromIso8601(options, result) → TimeIntervalCollection
engine/Source/Core/TimeIntervalCollection.js 995

Creates a new instance from an ISO 8601 time interval (start/end/duration).

Name | Type | Description
--- | --- | ---
`options` | object | Object with the following properties:
Name | Type | Default | Description
--- | --- | --- | ---
`iso8601` | string |  | An ISO 8601 interval.
`isStartIncluded` | boolean | `true` | optional `true` if start time is included in the interval, `false` otherwise.
`isStopIncluded` | boolean | `true` | optional `true` if stop time is included in the interval, `false` otherwise.
`leadingInterval` | boolean | `false` | optional `true` if you want to add a interval from Iso8601.MINIMUM_VALUE to start time, `false` otherwise.
`trailingInterval` | boolean | `false` | optional `true` if you want to add a interval from stop time to Iso8601.MAXIMUM_VALUE, `false` otherwise.
`dataCallback` | function |  | optional A function that will be return the data that is called with each interval before it is added to the collection. If unspecified, the data will be the index in the collection.
`result` | TimeIntervalCollection | optional An existing instance to use for the result.

##### Returns:

The modified result parameter or a new instance if none was provided.

#### static Cesium.TimeIntervalCollection.fromIso8601DateArray(options, result) → TimeIntervalCollection
engine/Source/Core/TimeIntervalCollection.js 1052

Creates a new instance from a ISO 8601 date array.

Name | Type | Description
--- | --- | ---
`options` | object | Object with the following properties:
Name | Type | Default | Description
--- | --- | --- | ---
`iso8601Dates` | Array.<string> |  | An array of ISO 8601 dates.
`isStartIncluded` | boolean | `true` | optional `true` if start time is included in the interval, `false` otherwise.
`isStopIncluded` | boolean | `true` | optional `true` if stop time is included in the interval, `false` otherwise.
`leadingInterval` | boolean | `false` | optional `true` if you want to add a interval from Iso8601.MINIMUM_VALUE to start time, `false` otherwise.
`trailingInterval` | boolean | `false` | optional `true` if you want to add a interval from stop time to Iso8601.MAXIMUM_VALUE, `false` otherwise.
`dataCallback` | function |  | optional A function that will be return the data that is called with each interval before it is added to the collection. If unspecified, the data will be the index in the collection.
`result` | TimeIntervalCollection | optional An existing instance to use for the result.

##### Returns:

The modified result parameter or a new instance if none was provided.

#### static Cesium.TimeIntervalCollection.fromIso8601DurationArray(options, result) → TimeIntervalCollection
engine/Source/Core/TimeIntervalCollection.js 1092

Creates a new instance from a ISO 8601 duration array.

Name | Type | Description
--- | --- | ---
`options` | object | Object with the following properties:
Name | Type | Default | Description
--- | --- | --- | ---
`epoch` | JulianDate |  | An date that the durations are relative to.
`iso8601Durations` | string |  | An array of ISO 8601 durations.
`relativeToPrevious` | boolean | `false` | optional `true` if durations are relative to previous date, `false` if always relative to the epoch.
`isStartIncluded` | boolean | `true` | optional `true` if start time is included in the interval, `false` otherwise.
`isStopIncluded` | boolean | `true` | optional `true` if stop time is included in the interval, `false` otherwise.
`leadingInterval` | boolean | `false` | optional `true` if you want to add a interval from Iso8601.MINIMUM_VALUE to start time, `false` otherwise.
`trailingInterval` | boolean | `false` | optional `true` if you want to add a interval from stop time to Iso8601.MAXIMUM_VALUE, `false` otherwise.
`dataCallback` | function |  | optional A function that will be return the data that is called with each interval before it is added to the collection. If unspecified, the data will be the index in the collection.
`result` | TimeIntervalCollection | optional An existing instance to use for the result.

##### Returns:

The modified result parameter or a new instance if none was provided.

#### static Cesium.TimeIntervalCollection.fromJulianDateArray(options, result) → TimeIntervalCollection
engine/Source/Core/TimeIntervalCollection.js 744

Creates a new instance from a JulianDate array.

Name | Type | Description
--- | --- | ---
`options` | object | Object with the following properties:
Name | Type | Default | Description
--- | --- | --- | ---
`julianDates` | Array.<JulianDate> |  | An array of ISO 8601 dates.
`isStartIncluded` | boolean | `true` | optional `true` if start time is included in the interval, `false` otherwise.
`isStopIncluded` | boolean | `true` | optional `true` if stop time is included in the interval, `false` otherwise.
`leadingInterval` | boolean | `false` | optional `true` if you want to add a interval from Iso8601.MINIMUM_VALUE to start time, `false` otherwise.
`trailingInterval` | boolean | `false` | optional `true` if you want to add a interval from stop time to Iso8601.MAXIMUM_VALUE, `false` otherwise.
`dataCallback` | function |  | optional A function that will be return the data that is called with each interval before it is added to the collection. If unspecified, the data will be the index in the collection.
`result` | TimeIntervalCollection | optional An existing instance to use for the result.

##### Returns:

The modified result parameter or a new instance if none was provided.

#### addInterval(interval, dataComparer)
engine/Source/Core/TimeIntervalCollection.js 310

Adds an interval to the collection, merging intervals that contain the same data and splitting intervals of different data as needed in order to maintain a non-overlapping collection. The data in the new interval takes precedence over any existing intervals in the collection.

Name | Type | Description
--- | --- | ---
`interval` | TimeInterval | The interval to add.
`dataComparer` | TimeInterval.DataComparer | optional A function which compares the data of the two intervals. If omitted, reference equality is used.

#### contains(julianDate) → boolean
engine/Source/Core/TimeIntervalCollection.js 212

Checks if the specified date is inside this collection.

Name | Type | Description
--- | --- | ---
`julianDate` | JulianDate | The date to check.

##### Returns:

`true` if the collection contains the specified date, `false` otherwise.

#### equals(right, dataComparer) → boolean
engine/Source/Core/TimeIntervalCollection.js 135

Compares this instance against the provided instance componentwise and returns `true` if they are equal, `false` otherwise.

Name | Type | Description
--- | --- | ---
`right` | TimeIntervalCollection | optional The right hand side collection.
`dataComparer` | TimeInterval.DataComparer | optional A function which compares the data of the two intervals. If omitted, reference equality is used.

##### Returns:

`true` if they are equal, `false` otherwise.

#### findDataForIntervalContainingDate(date) → object
engine/Source/Core/TimeIntervalCollection.js 199

Finds and returns the data for the interval that contains the specified date.

Name | Type | Description
--- | --- | ---
`date` | JulianDate | The date to search for.

##### Returns:

The data for the interval containing the specified date, or `undefined` if no such interval exists.

#### findInterval(options) → TimeInterval|undefined
engine/Source/Core/TimeIntervalCollection.js 279

Returns the first interval in the collection that matches the specified parameters. All parameters are optional and `undefined` parameters are treated as a don't care condition.

Name | Type | Description
--- | --- | ---
`options` | object | optional Object with the following properties:
Name | Type | Description
--- | --- | ---
`start` | JulianDate | optional The start time of the interval.
`stop` | JulianDate | optional The stop time of the interval.
`isStartIncluded` | boolean | optional `true` if `options.start` is included in the interval, `false` otherwise.
`isStopIncluded` | boolean | optional `true` if `options.stop` is included in the interval, `false` otherwise.

##### Returns:

The first interval in the collection that matches the specified parameters.

#### findIntervalContainingDate(date) → TimeInterval|undefined
engine/Source/Core/TimeIntervalCollection.js 188

Finds and returns the interval that contains the specified date.

Name | Type | Description
--- | --- | ---
`date` | JulianDate | The date to search for.

##### Returns:

The interval containing the specified date, `undefined` if no such interval exists.

#### get(index) → TimeInterval|undefined
engine/Source/Core/TimeIntervalCollection.js 162

Gets the interval at the specified index.

Name | Type | Description
--- | --- | ---
`index` | number | The index of the interval to retrieve.

##### Returns:

The interval at the specified index, or `undefined` if no interval exists as that index.

#### indexOf(date) → number
engine/Source/Core/TimeIntervalCollection.js 227

Finds and returns the index of the interval in the collection that contains the specified date.

Name | Type | Description
--- | --- | ---
`date` | JulianDate | The date to search for.

##### Returns:

The index of the interval that contains the specified date, if no such interval exists, it returns a negative number which is the bitwise complement of the index of the next interval that starts after the date, or if no interval starts after the specified date, the bitwise complement of the length of the collection.

#### intersect(other, dataComparer, mergeCallback) → TimeIntervalCollection
engine/Source/Core/TimeIntervalCollection.js 671

Creates a new instance that is the intersection of this collection and the provided collection.

Name | Type | Description
--- | --- | ---
`other` | TimeIntervalCollection | The collection to intersect with.
`dataComparer` | TimeInterval.DataComparer | optional A function which compares the data of the two intervals. If omitted, reference equality is used.
`mergeCallback` | TimeInterval.MergeCallback | optional A function which merges the data of the two intervals. If omitted, the data from the left interval will be used.

##### Returns:

A new TimeIntervalCollection which is the intersection of this collection and the provided collection.

#### removeAll()
engine/Source/Core/TimeIntervalCollection.js 175

Removes all intervals from the collection.

#### removeInterval(interval) → boolean
engine/Source/Core/TimeIntervalCollection.js 510

Removes the specified interval from this interval collection, creating a hole over the specified interval. The data property of the input interval is ignored.

Name | Type | Description
--- | --- | ---
`interval` | TimeInterval | The interval to remove.

##### Returns:

`true` if the interval was removed, `false` if no part of the interval was in the collection.

Need help? The fastest way to get answers is from the community and team on the Cesium Forum.