爲了找到兩個日期範圍的重疊,我明白我們需要類似的東西。Jodatime重疊方法不檢查等於
(thisStart <= otherEnd) && (otherStart <= thisEnd)
但是這裏面the overlaps method from Joda Time我看到
thisStart < otherEnd && otherStart < thisEnd
這不會支付一定的重疊條件。有覆蓋重疊使用時間< =
爲了找到兩個日期範圍的重疊,我明白我們需要類似的東西。Jodatime重疊方法不檢查等於
(thisStart <= otherEnd) && (otherStart <= thisEnd)
但是這裏面the overlaps method from Joda Time我看到
thisStart < otherEnd && otherStart < thisEnd
這不會支付一定的重疊條件。有覆蓋重疊使用時間< =
start
和end
候時刻任何其它方法。在喬達(以及任何時間範圍的理智執行)中,範圍在右側是半開放的,即它不包括結束時刻。
在這些條件下,Joda庫中的測試是正確的。
如果你仍然不服氣,嘗試拿出一個反例,其中重疊檢測不正確。
我在評論中分享了一個場景。可以說,這不是一個範圍本身。但我相信它對於很多常見業務場景非常有效。 – RBz
換句話說,加里森說半開放式的方法意味着開始*包含*而結尾* *排除*。這是定義時間跨度的常用和明智的方法。 –
請注意,JodaTime時間間隔在開始時是包含性的,在結尾處是排他性的,即'start <= x
kennytm
when thisStart = otherEnd = otherStart – RBz
另請參閱:[Joda時間中的包含日期範圍檢查](http://stackoverflow.com/questions/13583944/inclusive-date-range-check-in-joda-time?rq = 1 ) – Jesper