Package com.norconex.commons.lang.time

# Class DateModel

java.lang.Object
com.norconex.commons.lang.time.DateModel

public final class DateModel extends Object

Class abstracting several date and time implementations (`Date`, `LocalDate`, `ZonedDateTime`, etc.). The

## Default values

When unspecified, the following are the default values:

- Time units: zero
- Zone ID: UTC

When resolving a date with the specified time zone, it is set as the new time zone for the same time units. For example, setting PST as the time zone will change the time portion of a UTC date-time from "13:34 UTC" to "13:34 PST").

Modifying a time unit by calling "set" or "with" methods on it does not change any of the other time units. This includes the time zone. For instance, setting "America/Vancouver" time zone on a UTC date will result in the same clock time, but in a different time zone. E.g.,: `2022-11-10T04:49:51.000Z` will become `2022-11-10T04:49:51.000-08:00[America/Vancouver]`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `int`
  `day()`
  `DateModel`
  `day(int day)`
  `boolean`
  `equals(Object o)`
  `int`
  `hashCode()`
  `int`
  `hour()`
  `DateModel`
  `hour(int hour)`
  `int`
  `minute()`
  `DateModel`
  `minute(int minute)`
  `int`
  `month()`
  `DateModel`
  `month(int month)`
  `int`
  `nano()`
  `DateModel`
  `nano(int nano)`
  `static DateModel`
  `of(int year, int month, int day)`
  `static DateModel`
  `of(int year, int month, int day, int hour, int minute, int second)`
  `static DateModel`
  `of(long epoch)`
  `static DateModel`
  `of(@NonNull String dateStr)`
  Create a date model out of a date string representation, in the format defined by either `DateTimeFormatter.ISO_DATE_TIME` for date-time or `DateTimeFormatter.ISO_DATE` for date-only.
  `static DateModel`
  `of(@NonNull String dateStr, @NonNull ZonedDateTimeParser parser)`
  Create a date model out of a date string representation, based on settings defined in the supplied `ZonedDateTimeParser`.
  `static DateModel`
  `of(@NonNull Instant instant)`
  `static DateModel`
  `of(@NonNull LocalDate ld)`
  `static DateModel`
  `of(@NonNull LocalDateTime ldt)`
  `static DateModel`
  `of(@NonNull ZonedDateTime zdt)`
  `static DateModel`
  `of(Date date)`
  `int`
  `second()`
  `DateModel`
  `second(int second)`
  `boolean`
  `startOfDay()`
  `DateModel`
  `startOfDay(boolean startOfDay)`
  `Date`
  `toDate()`
  `long`
  `toEpoch()`
  `Instant`
  `toInstant()`
  `LocalDate`
  `toLocalDate()`
  `LocalDateTime`
  `toLocalDateTime()`
  `String`
  `toString()`
  Return the date as a string representation in the format defined by `DateTimeFormatter.ISO_DATE_TIME`.
  `ZonedDateTime`
  `toZonedDateTime()`
  `DateModel`
  `withDate(int year, int month, int day)`
  `DateModel`
  `withDay(int day)`
  `DateModel`
  `withHour(int hour)`
  `DateModel`
  `withMillisecond(int millisecond)`
  `DateModel`
  `withMinute(int minute)`
  `DateModel`
  `withMonth(int month)`
  `DateModel`
  `withNano(int nano)`
  `DateModel`
  `withSecond(int second)`
  `DateModel`
  `withStartOfDay(boolean startOfDay)`
  `DateModel`
  `withTime(int hour, int minute, int second)`
  `DateModel`
  `withYear(int year)`
  `DateModel`
  `withZoneId(@NonNull ZoneId zoneId)`
  `int`
  `year()`
  `DateModel`
  `year(int year)`
  `@NonNull ZoneId`
  `zoneId()`
  `DateModel`
  `zoneId(@NonNull ZoneId zoneId)`

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

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

- ## Method Details

  - ### of

    public static DateModel of(int year, int month, int day, int hour, int minute, int second)

  - ### of

    public static DateModel of(int year, int month, int day)

  - ### of

    public static DateModel of(@NonNull @NonNull ZonedDateTime zdt)

  - ### of

    public static DateModel of(@NonNull @NonNull LocalDateTime ldt)

  - ### of

    public static DateModel of(@NonNull @NonNull LocalDate ld)

  - ### of

    public static DateModel of(@NonNull @NonNull Instant instant)

  - ### of

    public static DateModel of(long epoch)

  - ### of

    public static DateModel of(Date date)

  - ### of

    public static DateModel of(@NonNull @NonNull String dateStr)
    Create a date model out of a date string representation, in the format defined by either `DateTimeFormatter.ISO_DATE_TIME` for date-time or `DateTimeFormatter.ISO_DATE` for date-only. If the time zone is not defined in the date string, UTC is assumed.
    Parameters:
      `dateStr` - date string
    Returns:
      date model
    Throws:
      `DateTimeException` - if the date string could not be parsed

  - ### of

    public static DateModel of(@NonNull @NonNull String dateStr, @NonNull @NonNull ZonedDateTimeParser parser)
    Create a date model out of a date string representation, based on settings defined in the supplied `ZonedDateTimeParser`.
    Parameters:
      `dateStr` - date string
      `parser` - the zoned date time parser
    Returns:
      date model
    Throws:
      `DateTimeException` - if the date string could not be parsed

  - ### withMillisecond

    public DateModel withMillisecond(int millisecond)

  - ### withDate

    public DateModel withDate(int year, int month, int day)

  - ### withTime

    public DateModel withTime(int hour, int minute, int second)

  - ### toDate

    public Date toDate()

  - ### toEpoch

    public long toEpoch()

  - ### toInstant

    public Instant toInstant()

  - ### toLocalDate

    public LocalDate toLocalDate()

  - ### toLocalDateTime

    public LocalDateTime toLocalDateTime()

  - ### toZonedDateTime

    public ZonedDateTime toZonedDateTime()

  - ### toString

    public String toString()
    Return the date as a string representation in the format defined by `DateTimeFormatter.ISO_DATE_TIME`. If the time zone is not defined, UTC is assumed.
    Overrides:
      `toString` in class `Object`
    Returns:
      date string
    Throws:
      `DateTimeException` - if the date string could not be rendered as a string

  - ### year

    public int year()

  - ### month

    public int month()

  - ### day

    public int day()

  - ### hour

    public int hour()

  - ### minute

    public int minute()

  - ### second

    public int second()

  - ### nano

    public int nano()

  - ### zoneId

    @NonNull public @NonNull ZoneId zoneId()

  - ### startOfDay

    public boolean startOfDay()

  - ### year

    public DateModel year(int year)
    Returns:
      `this`.

  - ### month

    public DateModel month(int month)
    Returns:
      `this`.

  - ### day

    public DateModel day(int day)
    Returns:
      `this`.

  - ### hour

    public DateModel hour(int hour)
    Returns:
      `this`.

  - ### minute

    public DateModel minute(int minute)
    Returns:
      `this`.

  - ### second

    public DateModel second(int second)
    Returns:
      `this`.

  - ### nano

    public DateModel nano(int nano)
    Returns:
      `this`.

  - ### zoneId

    public DateModel zoneId(@NonNull @NonNull ZoneId zoneId)
    Returns:
      `this`.

  - ### startOfDay

    public DateModel startOfDay(boolean startOfDay)
    Returns:
      `this`.

  - ### equals

    public boolean equals(Object o)
    Overrides:
      `equals` in class `Object`

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`

  - ### withYear

    public DateModel withYear(int year)
    Returns:
      `this`.

  - ### withMonth

    public DateModel withMonth(int month)
    Returns:
      `this`.

  - ### withDay

    public DateModel withDay(int day)
    Returns:
      `this`.

  - ### withHour

    public DateModel withHour(int hour)
    Returns:
      `this`.

  - ### withMinute

    public DateModel withMinute(int minute)
    Returns:
      `this`.

  - ### withSecond

    public DateModel withSecond(int second)
    Returns:
      `this`.

  - ### withNano

    public DateModel withNano(int nano)
    Returns:
      `this`.

  - ### withZoneId

    public DateModel withZoneId(@NonNull @NonNull ZoneId zoneId)
    Returns:
      `this`.

  - ### withStartOfDay

    public DateModel withStartOfDay(boolean startOfDay)
    Returns:
      `this`.