Package com.norconex.commons.lang.time
Class YearMonthDayInterval
java.lang.Object
com.norconex.commons.lang.time.YearMonthDayInterval
- All Implemented Interfaces:
Serializable
An immutable date interval where both the start and end are inclusive.
The start YearMonthDay instance must be before or the same date as
as the end YearMonthDay. Start and end YearMonthDay instances cannot be
null and start date must be before or the same date as
the end date.- Since:
- 1.3.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionYearMonthDayInterval(YearMonthDay start, YearMonthDay end) YearMonthDayInterval(String interval) Constructs a YearMonthDayInterval out of a string.YearMonthDayInterval(Calendar start, Calendar end) YearMonthDayInterval(Date start, Date end) -
Method Summary
Modifier and TypeMethodDescriptionbooleancontains(YearMonthDay ymd) Whether the YearMonthDay falls between this interval (inclusive endpoints).booleanWhether the date falls between this interval (inclusive endpoints).intgetDays()Gets the number of days between start and end dates, rounded down.getEnd()Gets the end date as midnight the day after to ensure all dates on the same day as this YearMonthDay are smaller than this returned exclusive date.intGets the number of months between start and end dates, rounded down.getStart()intgetYears()Gets the number of years between start and end dates, rounded down.toPeriod()Get a period equivalent to this YearMonthDay.toString()Gets the interval as a string of this format:yyyy-MM-dd - yyyy-MM-dd;
-
Constructor Details
-
YearMonthDayInterval
-
YearMonthDayInterval
Constructs a YearMonthDayInterval out of a string. The recommended string format isyyyy-MM-dd - yyyy-MM-dd, but any characters in between the start and end are accepted as long as there is a space after the start YearMontDay and before the end YearMonthDay.- Parameters:
interval- the interval to parse
-
YearMonthDayInterval
-
YearMonthDayInterval
-
-
Method Details
-
getStart
-
getStartDate
-
getEnd
-
getEndDate
-
getEndDateEndOfDay
Gets the end date as midnight the day after to ensure all dates on the same day as this YearMonthDay are smaller than this returned exclusive date. Useful for date range comparisons where typically the end date is exclusive.- Returns:
- midnight past the end date
-
contains
Whether the YearMonthDay falls between this interval (inclusive endpoints).- Parameters:
ymd- the YearMonthDay- Returns:
trueif YearMonthDay is included in this interval
-
contains
Whether the date falls between this interval (inclusive endpoints).- Parameters:
date- a date- Returns:
trueif the date is included in this interval
-
getYears
public int getYears()Gets the number of years between start and end dates, rounded down.- Returns:
- number of years
-
getMonths
public int getMonths()Gets the number of months between start and end dates, rounded down.- Returns:
- number of months
-
getDays
public int getDays()Gets the number of days between start and end dates, rounded down.- Returns:
- number of days
-
toPeriod
Get a period equivalent to this YearMonthDay.- Returns:
- period
- Since:
- 3.0.0
-
toString
Gets the interval as a string of this format:yyyy-MM-dd - yyyy-MM-dd;
-