I'm currently dealing with a lot of possibly indefinite date spans, ie.
StartDate EndDate
--------- ---------
01JAN1921 31DEC2009
10OCT1955 null
...
where the other end of the interval might be unknown or not defined. I've been working on little functions for detecting overlap, whether an interval is a subinterval of an other, calculating the gap between two intervals etc.
For example to detect overlaps, the problem is
S E S and E are the start and end of the interval
| | we're comparing to. Here both are known, but
s1------+---e1 | either could be null. The small s:s and e:s
| | s2....e2 define the intervals we're comparing to and
|s3--e3 | again we'd like to allow for open intervals.
| s4--+----e4
s5..e5| |
s6--+-------+--s7
| |
Based on questions related to detecting overlap with well defined intervals you need to check
Coalesce(S,Coalesce(e-1,0))<Coalesce(e,Coalesce(S+1,1))
AND Coalesce(E,Coalesce(s+1,0))>Coalesce(s,Coalesce(E-1,1))
I suppose this is a such common thing (concerning not only date or time intervals) that lots of people have been dealing with it. I'm looking for existing implementations, preferrably just functions based on basic comparison operations.