I got both a start and end date object on an event object. I got another object with the same start and end date objects in it. How do I test if they overlap each other?
views:
22answers:
2
+1
A:
There are some edge cases to consider here, but if you have two ranges [b1, e1] and [b2, e2], then they overlap if:
- b1 <= b2 <= e1 or
- b1 <= e2 <= e1 or
- b2 <= b1 <= e2 or
- b2 <= e2 <= e2
I think those cover it.
duffymo
2010-03-04 10:55:18
A:
function doesOverlap(e1, e2)
{
var e1start = e1.start.getTime();
var e1end = e1.end.getTime();
var e2start = e2.start.getTime();
var e2end = e2.end.getTime();
return (e1start > e2start && e1start < e2end ||
e2start > e1start && e2start < e1end)
}
Amarghosh
2010-03-04 11:01:19