Scenario 1
Time range 1 : 2016-12-06 11:00 to 2016-12-06 12:00
Time range 2 : 2016-12-06 10:00 to 2016-12-06 13:00
time range 1 is completely conflict with time range 2 and vice versa
Scenario 2
Time range 1 : 2016-12-06 11:00 to 2016-12-06 12:00
Time range 2 : 2016-12-06 11:00 to 2016-12-06 14:00
time range 1 is partial conflict with time range 2 and vice versa
Scenario 3
Time range 1 : 2016-12-06 11:00 to 2016-12-06 12:00
Time range 2 : 2016-12-06 09:00 to 2016-12-06 12:00
time range 1 is partial conflict with time range 2 and vice versa
How to accomplish above scenario using momentjs? I tried the isBetween
function but couldn't get it work.
I think moment-range is what you are looking for. Use its overlaps
and contains
function to make it. You can link to moment-range from the cdnjs servers.
var date1 = [moment("2016-12-06 11:00"), moment("2016-12-06 12:00")];
var date2 = [moment("2016-12-06 10:00"), moment("2016-12-06 13:00")];
var range = moment.range(date1);
var range2 = moment.range(date2);
// has overlapping
if(range.overlaps(range2)) {
if((range2.contains(range, true) || range.contains(range2, true)) && !date1[0].isSame(date2[0]))
alert("time range 1 is completely conflict with time range 2 and vice versa");
else
alert("time range 1 is partially conflict with time range 2 and vice versa");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With