Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare right-unbounded time intervals with joda-lib

Tags:

java

jodatime

Is it possible to determine wether two rigth-unbounded intervals (intervals with one boundary at infinity) overlap or not?

I've tried this (and other similar variations):

Instant now = new Instant(new Date().getTime());
Interval i2 = new Interval(now, (ReadableInstant) null);
Interval i1 = new Interval(now, (ReadableInstant) null);
boolean overlapping = i2.overlaps(i1);

But according to the docs, using null as a second parameter means "now" instead of "infinity".

EDIT: I've found this answer in the mailing list, so it seems to be impossible with Joda. I am now looking for alternative implementations.

like image 717
Guido Avatar asked Sep 19 '11 13:09

Guido


1 Answers

If both intervals start at t = -∞ , or if both intervals end at t = +∞, they will always overlap, regardless of the start date.

If interval A starts at t = -∞ and interval B ends at t = +∞, they overlap iff
A.start > B.start.

like image 109
Matt Ball Avatar answered Sep 25 '22 23:09

Matt Ball