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?
You could resolve the date down into a long
and use an IntervalTree. Here's one I made earlier.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With