Joda-time has an Interval class, which is a range between DateTimes. What can be used for a range of LocalDates?
I want an object that represents, for example "from 1/1/2011 to 10/1/2011", without the time (or timezones) ever coming into the picture.
As far as I see, joda-time doesn't have anything built in for that. If there doesn't exist anything for it, and we'd create it, what should it look like? Most importantly, which interfaces from joda-time could it implement to best integrate into the other types, staying consistent with the joda-time design? Would it make sense for it to implement ReadableInterval
, where getStart
and getEnd
return DateMidnight
?
So the short answer to your question is: YES (deprecated).
LocalDate is an immutable datetime class representing a date without a time zone. LocalDate implements the ReadablePartial interface. To do this, the interface methods focus on the key fields - Year, MonthOfYear and DayOfMonth. However, all date fields may in fact be queried.
Joda-Time is an API created by joda.org which offers better classes and having efficient methods to handle date and time than classes from java. util package like Calendar, Gregorian Calendar, Date, etc. This API is included in Java 8.0 with the java.
A date without a time-zone in the ISO-8601 calendar system, such as 2007-12-03 . LocalDate is an immutable date-time object that represents a date, often viewed as year-month-day.
I personnaly use the Range class from Guava.
It supports open ended ranges. It is also possible to specify included or excluded bounds. Among other numerous possibilities, those allow to easily represent "before a date" or "after a date".
Example for open-ended intervals.
Range<LocalDate> before2010 = Range.atMost(new LocalDate("2009-12-31")); Range<LocalDate> alsoBefore2010 = Range.lessThan(new LocalDate("2010-01-01"));
It also offerts easy testing predicates, like contains and containsAll, and an intersection operation. All this tested and maintained.
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