My function for checking if two range of dates are overlapping doesn't work when I use YYYY-MM-DDTHH:MM:SSZ
format
The second example of the date rent2
and book2
have the same date, but the time is different, so it should not detect the overlapping
const rent = {
start: new Date("2019-03-10"),
end: new Date("2019-03-14")
}
const book = {
start: new Date("2019-03-15"),
end: new Date("2019-03-18"),
}
const rent2 = {
start: new Date("2019-03-10T01:00:00Z"),
end: new Date("2019-03-14T10:00:00Z")
}
const book2 = {
start: new Date("2019-03-10T12:00:00Z"),
end: new Date("2019-03-14T15:00:00Z"),
}
function isOverlapping(startOne, endOne, startTwo, endTwo) {
startOne = startOne.getTime();
startTwo = startTwo.getTime();
endOne = endOne.getTime();
endTwo = endTwo.getTime();
return !(endOne <= startTwo || startOne >= endTwo);
}
console.log("First: ", isOverlapping(rent.start, rent.end, book.start, book.end));
console.log("Second: ", isOverlapping(rent2.start, rent2.end, book2.start, book2.end));