Constructor
new TimePeriodList(timePeriodList)
Creates a new TimePeriodList.
Parameters:
Name | Type | Description |
---|---|---|
timePeriodList |
Array.<TimePeriod> | An array of TimePeriod object. |
Methods
contains(timePeriod) → {Boolean}
Returns true if the provided timePeriod is fully contained within any timePeriod of this timePeriodList.
Parameters:
Name | Type | Description |
---|---|---|
timePeriod |
TimePeriod | The timePeriod wants to check if is fully contained within any timePeriod of this timePeriodList or not. |
Throws:
-
Throws an error if the provided timePeriod is not a TimePeriod object.
- Type
- TypeError
Returns:
Returns true if the provided timePeriod is fully contained within any timePeriod of this timePeriodList, else return false.
- Type
- Boolean
divideAllByLength(divisorInMins) → {TimePeriodList}
Divides all the time period in this timePeriodList into periods with same duration provided.
Parameters:
Name | Type | Description |
---|---|---|
divisorInMins |
number | The duration of divided periods. |
Throws:
-
-
Throws an error if divisorInMins is not a number.
- Type
- TypeError
-
-
-
Throws an error if divisorInMins is less than or equals to 0.
- Type
- RangeError
-
Returns:
The TimePeriodList object contain subtracted timePeriods.
- Type
- TimePeriodList
forEach(callback)
Iterates over each time period in the list and applies the provided callback function.
The callback is invoked with three arguments: the current time period, the index, and the entire timePeriodList.
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | A function that is executed for each time period. The callback receives the following arguments: - {TimePeriod} currentTimePeriod - The current time period being processed. - {number} index - The index of the current time period. - {TimePeriod[]} timePeriodList - The entire list of time periods. |
get(index) → {TimePeriod}
Gets the first (index + 1) timePeriod in timePeriodList.
Parameters:
Name | Type | Description |
---|---|---|
index |
Number | The index wants to in this timePeriodList. |
Returns:
The first (index + 1) timePeriod in timePeriodList.
- Type
- TimePeriod
getAll() → {Array.<TimePeriod>}
Gets an array contains all the timePeriod in this timePeriodList.
Returns:
The array contain all the timePeriod in this timePeriodList.
- Type
- Array.<TimePeriod>
mergeMultiple(timePeriodList) → {TimePeriodList}
Merges all timePeriod, until no overlap bewteen every timePeriod.
Parameters:
Name | Type | Description |
---|---|---|
timePeriodList |
Array.<TimePeriod> | TimePeriodList | The timePeriods wants to merge into this timePeriodList. This can be: - An array of timePeriod. - TimePeriodList object. |
Throws:
-
Throws an error if the provided timePeriodList or this timePeriodList having not TimePeriod object.
- Type
- TypeError
Returns:
The TimePeriodList object contain merged timePeriod.
- Type
- TimePeriodList
subtractMultiple(timePeriodToSubtractList, minimumDurationInMinsopt) → {TimePeriodList}
Subtracts the overlapped time period between provided timePeriodList and this timePeriodList from this timePeriodList.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
timePeriodToSubtractList |
Array.<TimePeriod> | The subtrahend. | ||
minimumDurationInMins |
Number |
<optional> |
0 | The optional minimum duration of the returned timePeriods. |
Throws:
-
-
Throws an error if timePeriod is not a TimePeriod object.
- Type
- TypeError
-
-
-
Throws an error if minimumDurationInMins is not a number.
- Type
- TypeError
-
-
-
Throws an error if minimumDurationInMins is less than 0.
- Type
- RangeError
-
Returns:
The TimePeriodList object contain subtracted timePeriods.
- Type
- TimePeriodList
trimAllEnd(durationInMins) → {TimePeriodList}
Trims the end of all timePeriod in this timePeriodList by the provided duration.
Parameters:
Name | Type | Description |
---|---|---|
durationInMins |
Number | The amount of time to trim from the end. |
Throws:
-
-
Throws an error if the provided durationInMins is not a number.
- Type
- TypeError
-
-
-
Throws an error if the provided durationInMins is less than 0.
- Type
- RangeError
-
Returns:
The trimmed TimePeriodList, if the duration exceeds the current time span a timePeriod where start equals end is return.
- Type
- TimePeriodList