tamaki.mes.utils.calculateOverlappingDuration
Description
Returns the overlapping duration between two intervals. Each interval is defined by a start and end
value (typically epoch milliseconds). The overlap is the difference between the latest start and the
earliest end; if the intervals do not overlap, the function returns 0. The result is in the same
units as the inputs.
Syntax
tamaki.mes.utils.calculateOverlappingDuration(start1, end1, start2, end2)
Parameters
| Parameter | Type | Nullable | Description |
|---|---|---|---|
start1 | Number | False | Start of the first interval (epoch time). |
end1 | Number | False | End of the first interval (epoch time). |
start2 | Number | False | Start of the second interval (epoch time). |
end2 | Number | False | End of the second interval (epoch time). |
Returns
A Number: the overlapping duration in the same units as the inputs, or 0 if there is no overlap.
Code Examples
# Two 1-hour windows overlapping by 30 minutes (epoch millis)
overlapMs = tamaki.mes.utils.calculateOverlappingDuration(
0, 3600000,
1800000, 5400000
)
# 1800000 (30 minutes)