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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: