私は現在、多くのおそらく無期限の日付スパンを扱っています。
StartDate EndDate
--------- ---------
01JAN1921 31DEC2009
10OCT1955 null
...
間隔のもう一方の端が不明であるか、定義されていない可能性があります。私は、間隔が他の間隔のサブ間隔であるかどうか、2つの間隔間のギャップを計算するなど、オーバーラップを検出するための小さな関数に取り組んできました。
たとえば、重複を検出する場合、問題は次のとおりです。
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
| |
明確に定義された間隔との重複の検出に関連する質問に基づいて、確認する必要があります
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))
これは(日付や時間の間隔だけでなく)多くの人が扱っているような一般的なことだと思います。私は既存の実装、できれば基本的な比較操作に基づく関数だけを探しています。