BartlomiejSkwira
11/14/2013 - 11:51 AM

date range intersection

date range intersection

Let ConditionA Mean DateRange A Completely After DateRange B (True if StartA > EndB)

Let ConditionB Mean DateRange A Completely Before DateRange B (True if EndA < StartB)

Then Overlap exists if Neither A Nor B is true ( If one range is neither completely after the other, nor completely before the other, then they must overlap)

Now deMorgan's law says that:

Not (A Or B) <=> Not A And Not B

Which means (StartA <= EndB) and (EndA >= StartB)

NOTE: This includes conditions where the edges overlap exactly. If you wish to exclude that, change the >= operators to >, and <= to <