Skip to content

Instantly share code, notes, and snippets.

@BartlomiejSkwira
Created November 14, 2013 11:51
Show Gist options
  • Select an option

  • Save BartlomiejSkwira/7465565 to your computer and use it in GitHub Desktop.

Select an option

Save BartlomiejSkwira/7465565 to your computer and use it in GitHub Desktop.
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 <
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment