import toDate from '../toDate/index' ; import type { Interval } from '../types' ; import requiredArgs from '../_lib/requiredArgs/index' ; name category summary description param { Interval } intervalLeft - the first interval to compare. See [Interval] https param { Interval } intervalRight - the second interval to compare. See [Interval] https param options param { Boolean } options . inclusive returns { Boolean } throws throws throws example example example example export default function areIntervalsOverlapping ( dirtyIntervalLeft , dirtyIntervalRight , options = { inclusive : false } ) { requiredArgs ( 2 , arguments ) ; const intervalLeft = dirtyIntervalLeft || { } ; const intervalRight = dirtyIntervalRight || { } ; const leftStartTime = toDate ( intervalLeft . start ) . getTime ( ) ; const leftEndTime = toDate ( intervalLeft . end ) . getTime ( ) ; const rightStartTime = toDate ( intervalRight . start ) . getTime ( ) ; const rightEndTime = toDate ( intervalRight . end ) . getTime ( ) ; if ( ! ( leftStartTime <= leftEndTime && rightStartTime <= rightEndTime ) ) { throw new RangeError ( 'Invalid interval' ) ; } if ( options . inclusive ) { return leftStartTime <= rightEndTime && rightStartTime <= leftEndTime ; } return leftStartTime < rightEndTime && rightStartTime < leftEndTime ; }