1

For finding the overlap of two date ranges i understand we need something like.

(thisStart <= otherEnd ) && (otherStart <= thisEnd)

But inside the overlaps method from Joda Time I see

thisStart < otherEnd && otherStart < thisEnd

This wont cover certain overlap conditions. Is there any other method which cover overlap using <=

kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
RBz
  • 896
  • 3
  • 17
  • 34
  • 1
    Note that JodaTime interval is inclusive at the start and exclusive at the end, i.e. `start <= x < end`. – kennytm Mar 09 '17 at 06:44
  • when thisStart = otherEnd = otherStart – RBz Mar 09 '17 at 06:46
  • See also: [Inclusive Date Range Check in Joda Time](http://stackoverflow.com/questions/13583944/inclusive-date-range-check-in-joda-time?rq=1) – Jesper Mar 09 '17 at 07:40
  • @Jesper I did see your answer. Using before and after is one way to meet my requirement. I was just wondering why overlap won't do it. – RBz Mar 09 '17 at 09:16

1 Answers1

1

start and end designate instants in time. In Joda (and any sane implementation of a time range) a range is half-open on the right, i.e. it does not include the end-instant.

Under those conditions, the test in the Joda library is correct.

If you're still unconvinced, try to come up with a counterexample where overlap is not detected correctly.

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
  • I have shared a scenario in the comments. One can say that's not a range per se. But i believe its very valid for a lot of common business scenarios. – RBz Mar 09 '17 at 06:54
  • 3
    In other words, Garrison is saying the Half-Open approach means the beginning is *inclusive* while the ending is *exclusive*. This is a common, and wise, approach to define spans of time. – Basil Bourque Mar 09 '17 at 07:05