Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java 8 class to represent time intervals [duplicate]

Tags:

java

date

time

Java 8 introduced a new Time & Date API, with classes like Period or Duration.

Now I'm looking for a class to represent date intervals, e.g. "from 4th August 2016 to 8th August 2016" and answer the question: do these intervals overlap. Period doesn't seem to satisfy this, since it works in an affine way, not knowing where the interval has started, only how long it takes.

Is there any Java 8 standard library class to suit my needs? Or do I have to write my own?

like image 932
marmistrz Avatar asked Apr 13 '16 14:04

marmistrz


1 Answers

You could resolve the date down into a long and use an IntervalTree. Here's one I made earlier.

like image 96
OldCurmudgeon Avatar answered Nov 09 '22 23:11

OldCurmudgeon