Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
408 views
in Technique[技术] by (71.8m points)

java - LocalDate interval in Joda-time

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...