Constructor
new TimePeriod(startDateTime, endDateTime)
Creates a new TimePeriod.
Parameters:
Name | Type | Description |
---|---|---|
startDateTime |
Date | The start time of the time period. |
endDateTime |
Date | The end time of the time period. |
Throws:
-
-
Throws an error if startDateTime > endDateTime.
- Type
- RangeError
-
-
-
Throws an error if the startDateTime or endDateTime is not a valid Date object.
- Type
- TypeError
-
Methods
contains(timePeriod) → {Boolean}
Returns true if the provided timePeriod is fully contained within this timePeriod.
Parameters:
Name | Type | Description |
---|---|---|
timePeriod |
TimePeriod | The timePeriod wants to check if is fully contained within this timePeriod 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 this timePeriod, else return false.
- Type
- Boolean
divideByLength(divisorInMins) → {Array.<TimePeriod>}
Divides a timePeriod 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:
An array of TimePeriod objects with duration = divisorInMins.
- Type
- Array.<TimePeriod>
merge(timePeriod) → {TimePeriod}
Merges two timePeriod into one period if no overlap bewteen two timePeriod, this timePeriod will be return.
Parameters:
Name | Type | Description |
---|---|---|
timePeriod |
TimePeriod | The timePeriod wants to merge into this timePeriod. |
Throws:
-
Throws an error if the provided timePeriod is not a TimePeriod object.
- Type
- TypeError
Returns:
The merged timePeriod.
- Type
- TimePeriod
subtract(timePeriod, minimumDurationInMinsopt) → {Array.<TimePeriod>}
Subtracts the overlapped time period bewteen this timePeriod and provided timePeriod from this timePeriod.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
timePeriod |
TimePeriod | The subtrahend. | ||
minimumDurationInMins |
Number |
<optional> |
0 | The optional minimum duration of the returned timePeriods. |
Throws:
-
-
Throws an error if minimumDurationInMins is less than 0.
- Type
- RangeError
-
-
-
Throws an error if minimumDurationInMins is not a number.
- Type
- TypeError
-
-
-
Throws an error if timePeriod is not a TimePeriod object.
- Type
- TypeError
-
Returns:
An array of remaining timePeriod after subtraction.
- Type
- Array.<TimePeriod>
trimEnd(durationInMins) → {TimePeriod}
Trims the end of this timePeriod 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 timePeriod, or a timePeriod where start equals end if the duration exceeds the current time span.
- Type
- TimePeriod
(static) isNotLessThanDuration(startDateTime, endDateTime, duration) → {Boolean}
Compares the duration of a pair of start time and end time.
Parameters:
Name | Type | Description |
---|---|---|
startDateTime |
Date | The start time of the time period. |
endDateTime |
Date | The end time of the time period. |
duration |
Number | The duration to compare. |
Throws:
-
-
Throws an error if duration is not a number.
- Type
- TypeError
-
-
-
Throws an error if duration is less than 0.
- Type
- RangeError
-
-
-
Throws an error if startDateTime > endDateTime.
- Type
- RangeError
-
Returns:
If duration of start time and end time is greater or equals to provided duration, or duration = 0 return true, else false.
- Type
- Boolean