Package com.norconex.commons.lang.time
Class YearMonthDayInterval
- java.lang.Object
-
- com.norconex.commons.lang.time.YearMonthDayInterval
-
- All Implemented Interfaces:
Serializable
public final class YearMonthDayInterval extends Object implements Serializable
An immutable date interval where both the start and end are inclusive, unless stated otherwise. Start and end YearMonthDay instances cannot benull
and start date must be before or the same date as the end date.- Since:
- 1.3.0
- Author:
- Pascal Essiembre
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description YearMonthDayInterval(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
contains(YearMonthDay ymd)
Whether the YearMonthDay falls between this interval (inclusive endpoints).boolean
contains(Date date)
Whether the date falls between this interval (inclusive endpoints).int
getDays()
Gets the number of days between start and end dates, rounded down.YearMonthDay
getEnd()
Date
getEndDate()
Date
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.int
getMonths()
Gets the number of months between start and end dates, rounded down.YearMonthDay
getStart()
Date
getStartDate()
int
getYears()
Gets the number of years between start and end dates, rounded down.String
toString()
Gets the interval as a string of this format:yyyy-MM-dd - yyyy-MM-dd
;
-
-
-
Constructor Detail
-
YearMonthDayInterval
public YearMonthDayInterval(YearMonthDay start, YearMonthDay end)
-
YearMonthDayInterval
public YearMonthDayInterval(String interval)
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
-
-
Method Detail
-
getStart
public YearMonthDay getStart()
-
getStartDate
public Date getStartDate()
-
getEnd
public YearMonthDay getEnd()
-
getEndDate
public Date getEndDate()
-
getEndDateEndOfDay
public Date 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
public boolean contains(YearMonthDay ymd)
Whether the YearMonthDay falls between this interval (inclusive endpoints).- Parameters:
ymd
- the YearMonthDay- Returns:
true
if YearMonthDay is included in this interval
-
contains
public boolean contains(Date date)
Whether the date falls between this interval (inclusive endpoints).- Parameters:
date
- a date- Returns:
true
if 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
-
-