LocalDate interval in Joda-time

前端 未结 6 1891
误落风尘
误落风尘 2020-12-10 23:54

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

6条回答
  •  不知归路
    2020-12-11 00:25

    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 before2010 = Range.atMost(new LocalDate("2009-12-31"));
    Range 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.

提交回复
热议问题