Thursday, April 28, 2016

Checking to see if two periods of time overlap/interfere with each other.

Here are all possible cases/scenerios of two periods T1 and T2

Case 1
T1 |------|
T2          |------|

Case 2
T1 |------|
T2     |------|

Case 3
T1 |---------|
T2   |-----|

Case 4
T1   |----|
T2 |---------|

Case 5
T1    |------|
T2 |------|

Case 6
T1        |------|
T2 |-----|

In these cases, if we carefully observe we see that in Case 2,3,4 and 5 the periods overlap each other.  Where case 1 and case 6 do not.

If we carefully look at all 4 cases that overlap we will notice that for these cases this condition happens (T1.start < T2.end) AND (T1.end > T2.start)so to check for overlap we simply apply the above bolded check.