period compare array of date overlap code example

Example: period compare array of date overlap

checkDateTimeOverlap = (dateTimes)=>{
        let isOverlap = false;
        dateTimes.forEach((time,i) => {
            let  st1 = time[0];
            let  et1 = time[1];
          
            dateTimes.forEach((time2,j) => {               
                if(i != j){
                    let st2 = time2[0];
                    let et2 = time2[1];
                    if (st1 >= st2 && st1 <= et2 || et1 >= st2 && et1 <= et2 || st2 >= st1 && st2 <= et1 || et2 >= st1 && et2 <= et1) {
                        isOverlap =  true;
                    }else{
                        isOverlap =  false;
                    }
                }
            })
        }); 

        return isOverlap;
    }

Tags:

Misc Example