Please pass unixtime in array like below example
var subevent = [
{
start: Mon Jun 26 2017 10:15:00 GMT+0530 (India Standard Time),
startunix: 1498452300000,
end: Mon Jun 26 2017 11:15:00 GMT+0530 (India Standard Time),
endunix: 1498455900000
},
{
start: Mon Jun 26 2017 11:15:00 GMT+0530 (India Standard Time),
startunix: 1498455900000,
end: Mon Jun 26 2017 12:15:00 GMT+0530 (India Standard Time),
endunix: 1498459500000
}
]
then sorting array in time ascending order
var sortedArray = subevent.sort(function(a,b){
return a.startunix - b.startunix;
});
use sorted array in for loop and store endunix time in one variable lastEndTime
and check current iteration start time with lastEndTime
variable like below code
var errorFlag = 0;
var lastEndTime;
for(var i=0; i<sortedArray.length; i++) {
var currentStartTime;
if( sortedArray[i].endunix <= sortedArray[i].startunix ){
alert('time slot conflict')
errorFlag = 1;
break;
}
if( !lastEndTime ) {
lastEndTime = sortedArray[i].endunix;
//console.log(" i where last end time not exists = "+i+" lastEndTime "+lastEndTime);
} else {
currentStartTime = sortedArray[i].startunix;
//console.log(" i where last end time exists = "+i+" currentStartTime "+currentStartTime+" lastEndTime "+lastEndTime );
if ( currentStartTime < lastEndTime ) {
alert('time overlapping')
errorFlag = 1;
break;
}
lastEndTime = sortedArray[i].endunix;
}
}
console.log(errorFlag);
there is also display alert or errorflag, if alert display or errorflag is one then something went wrong otherwise everything is ok.