I am trying to determine if two sets of date/time range overlap or not --- returning BOOLEAN value.
Consider the following cases:
NOTE: I turn each date/time string below (e.g. 24-JAN-17 07:00
) to timestamp using strtotime()
Expression used for each case is:
$isOverlapping = (s1 < e2 && s2 < e1)
Case 1:
Let (s1, e1) be defined as (24-JAN-17 07:00, 24-JAN-17 17:00)
Let (s2, e2) be defined as (24-JAN-17 16:30, 24-JAN-17 17:30)
Result:
TRUE
(which is correct)
Case 2:
Let (s1, e1) be defined as (24-JAN-17 07:00, 24-JAN-17 17:00)
Let (s2, e2) be defined as (24-JAN-17 16:30, 25-JAN-17 07:00)
Result:
TRUE
(which is correct)
Case 3:
Let (s1, e1) be defined as (24-JAN-17 07:00, 24-JAN-17 17:00)
Let (s2, e2) be defined as (24-JAN-17 17:00, 25-JAN-17 07:30)
Result:
FALSE
(which is INCORRECT)
It is my understanding that it does this because (in case of #3 above), it overflows into the next day... but if that is the case, why does it work for Case 2
? (is it because the overlap happens on the same day, contrary to Case 3
?)
Regardless, my question is, how to tweak my expression, such that it covers Case 3, above?
Any and all help appreciated! Thank you!
I have already reviewed the following threads, but to no avail:
Determine Whether Two Date Ranges Overlap
Determining if two time ranges overlap at any point (Specifically: https://stackoverflow.com/a/13387860/7458905)