How can I compare whether two datetimes are the same or at least overlap?
For example, let’s say we have the following two sets of start and stop times:
Start time: 2011-07-21 9:00am Stop time: 2011-07-21 10:00am
Start time: 2011-07-21 9:05am Stop time: 2011-07-21 10:30am
The datetimes do not match exactly, so I can’t do a straight equality test. However, for my purposes the datetimes overlap is sufficient to be deemed a match, how can I test for this type of overlap?
I highly recommend to use JodaTime and its overlap method.
From javadoc, it will not only tell you if it two intervals overlap. But it tells you what the overlapping interval is.