Monthly Archives: October, 2012

The easy way to discover overlapping time spans

//b overlaps a
(a.start < b.start AND a.start < b.end AND a.end > b.start AND a.end < b.end)
OR

//a overlaps b
(a.start > b.start AND a.start < b.end AND a.end > b.start AND a.end > b.end)
OR

//b includes a
(a.start > b.start AND a.start < b.end AND a.end > b.start AND a.end < b.end)
OR

//a includes b
(a.start < b.start AND a.start < b.end AND a.end > b.start AND a.end > b.end)

=

(a.start < b.end AND a.end > b.start)
AND
(
a.start < b.start AND a.end < b.end
OR
a.start > b.start AND a.end > b.end
OR
a.start > b.start AND a.end < b.end
OR
a.start < b.start AND a.end > b.end
)

=

a.start < b.end AND a.end > b.start

Thats all to discover whether time span a and b overlapping eachother in any way.

(to be more precise replace “>” by “>=”)

Advertisements