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. 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:
  - `Period`
  - 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

  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.
  `Period`
  `toPeriod()`
  Get a period equivalent to this YearMonthDay.
  `String`
  `toString()`
  Gets the interval as a string of this format: `yyyy-MM-dd - yyyy-MM-dd`;

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### YearMonthDayInterval

    public YearMonthDayInterval(YearMonthDay start, YearMonthDay end)

  - ### YearMonthDayInterval

    public YearMonthDayInterval(String interval)
    Constructs a YearMonthDayInterval out of a string. The recommended string format is `yyyy-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

    public YearMonthDayInterval(Date start, Date end)

  - ### YearMonthDayInterval

    public YearMonthDayInterval(Calendar start, Calendar end)

- ## Method Details

  - ### 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

  - ### toPeriod

    public Period toPeriod()
    Get a period equivalent to this YearMonthDay.
    Returns:
      period
    Since:
      3.0.0

  - ### toString

    public String toString()
    Gets the interval as a string of this format: `yyyy-MM-dd - yyyy-MM-dd`;
    Overrides:
      `toString` in class `Object`
    Returns:
      interval as string