com.comtrade.ecm.engine.datatypes

## Class DateTime

- java.lang.Object
- - com.comtrade.ecm.engine.datatypes.DateTime

-     public class DateTime
      extends java.lang.Object

  Object that keeps information of both :
  - a calendar date : a year, a month [1-12], and a dayOfMonth [1-28|29|30|31].
  - a time (in a day) : an hour [0-23], a minute [0-59], a second [0-59], and a nano [0-999_999_999].
  Month is INTENTIONALLY returned as an int, in order to avoid dependency on `Month`.
  There are no public constructors, all of the objects must be created using factory methods.
  See Also:
    Serialized Form

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `DateTime.Unit` Units to be used in `DateTime`-mathemathics.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `DEFAULT_DATE_TIME_FORMAT` A date-format-pattern to be used for formatting, if no other is defined.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `DateTime` | `add(long amountToAdd, DateTime.Unit unit)` Changes a current value of an object for `amountToAdd` units of `unit`
    `int` | `compareTo(Date other)` Compares an object with another `Date` object.
    `int` | `compareTo(DateTime other)` Compares an object with another `DateTime`-object.
    `boolean` | `equals(java.lang.Object other)` Compares an object to another `DateTime` object.
    `int` | `getDay()`
    `int` | `getHour()`
    `int` | `getMillisecond()`
    `int` | `getMinute()`
    `int` | `getMonth()` Month is INTENTIONALLY returned as an int, in order to avoid dependency on `Month`
    `int` | `getNano()`
    `int` | `getSecond()`
    `int` | `getYear()`
    `int` | `hashCode()` Hashcode of an object. Hashcode of an object will be a hashcode of its value-container object `value`
    `boolean` | `isSameDateAs(Date otherDate)` Compares an object to another `Date`-object.
    `static DateTime` | `now()` Creating a datetime from a current date and current time.
    `static DateTime` | `of(Date date)` Creating a datetime from a `Date`.
    `static DateTime` | `of(java.util.Date datetime)` Creating a datetime from a `Date`.
    `static DateTime` | `of(DateTime datetime)` Creating a datetime from another `DateTime`.
    `static DateTime` | `of(Date date, Time time)` Creating a datetime from a `Date` and a `Time`
    `static DateTime` | `of(java.time.LocalDate date)` Creating a datetime from a `LocalDate`.
    `static DateTime` | `of(java.time.LocalDateTime datetime)` Creating a datetime from a `DateTime`
    `Date` | `toDate()`
    `DateTime` | `toEndOfDay()`
    `DateTime` | `toEndOfYear()`
    `java.lang.String` | `toFormattedString(java.time.format.DateTimeFormatter formatter)` Method which formats a date using `formatter`.
    `java.util.Date` | `toJavaUtilDate()` Converts an object to `Date`.
    `java.time.LocalDateTime` | `toLocalDateTime()` Converts an object to `LocalDateTime`.
    `DateTime` | `toStartOfDay()`
    `DateTime` | `toStartOfYear()`
    `java.lang.String` | `toString()` Converts to `String`, using `DEFAULT_FORMATTER`.
    `static java.lang.String` | `toString(DateTime dateTime, java.time.format.DateTimeFormatter formatter)` Converts `dateTime` to `String`, using `formatter`, following all other rules of formatting.
    `java.lang.String` | `toString(java.time.format.DateTimeFormatter formatter)` Converts to `String`, using `formatter`.
    `static java.lang.String` | `toString(DateTime dateTime, java.util.Locale locale)` Converts `dateTime` to `String`, using `locale`, following all other rules of formatting.
    `static java.lang.String` | `toString(DateTime dateTime, java.lang.String formatDescription)` Converts `dateTime` to `String`, using `formatDescription`, following all other rules of formatting.
    `java.lang.String` | `toString(java.util.Locale locale)` Converts to `String`, using `locale`.
    `java.lang.String` | `toString(java.lang.String formatDescription)` Converts to `String`, using a `DateTimeFormatter` defined by `formatDescription`.
    `Time` | `toTime()`

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

      `getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT_DATE_TIME_FORMAT

          public static final java.lang.String DEFAULT_DATE_TIME_FORMAT

      A date-format-pattern to be used for formatting, if no other is defined.
      See Also:
        Constant Field Values

  - ### Method Detail

    - #### of

          public static DateTime of(java.time.LocalDateTime datetime)

      Creating a datetime from a `DateTime`
      Parameters:
        `datetime` - A `LocalDateTime`-object that defines initial values for a newly created `DateTime` object
      Returns:
        A newly created `DateTime` object

    - #### of

          public static DateTime of(Date date,
                                    Time time)

      Creating a datetime from a `Date` and a `Time`
      Parameters:
        `date` - Date part of an object that should be created
        `time` - Time part of an object that should be created
      Returns:
        A newly created `DateTime` object

    - #### of

          public static DateTime of(Date date)

      Creating a datetime from a `Date`. Time-part will be zeroed.
      Parameters:
        `date` - Date part of an object that should be created
      Returns:
        A newly created `DateTime` object

    - #### of

          public static DateTime of(java.time.LocalDate date)

      Creating a datetime from a `LocalDate`. Time-part will be zeroed.
      Parameters:
        `date` - Date part of an object that should be created
      Returns:
        A newly created `DateTime` object

    - #### of

          public static DateTime of(DateTime datetime)

      Creating a datetime from another `DateTime`.
      Parameters:
        `datetime` - A `DateTime`-object that we are cloning
      Returns:
        A newly created `DateTime` object

    - #### of

          public static DateTime of(java.util.Date datetime)

      Creating a datetime from a `Date`.
      Parameters:
        `datetime` - A Date and Time info defined by `Date` object.
      Returns:
        A newly created `DateTime` object

    - #### now

          public static DateTime now()

      Creating a datetime from a current date and current time.
      Returns:
        A newly created `DateTime` object

    - #### toStartOfYear

          public DateTime toStartOfYear()

      Returns:
        The first datetime of a year of this `DateTime`-object.

    - #### toEndOfYear

          public DateTime toEndOfYear()

      Returns:
        The last datetime of a year of this `DateTime`-object.

    - #### toStartOfDay

          public DateTime toStartOfDay()

      Returns:
        The earliest time of an objects date (e.g. a beggining of a day).

    - #### toEndOfDay

          public DateTime toEndOfDay()

      Returns:
        The lastest time of an objects date (e.g. a end of a day).

    - #### getYear

          public int getYear()

      Returns:
        The year of this `DateTime`-object

    - #### getMonth

          public int getMonth()

      Month is INTENTIONALLY returned as an int, in order to avoid dependency on `Month`
      Returns:
        the month-of-year (from 1 to 12) of this `Date`-object.

    - #### getDay

          public int getDay()

      Returns:
        the day-of-month (from 1 to 28|29|30|31) of this `DateTime`-object.

    - #### getHour

          public int getHour()

      Returns:
        The hour-of-day (from 0 to 23) of this `Time`-object

    - #### getMinute

          public int getMinute()

      Returns:
        the the minute-of-hour (from 0 to 59) of this `Time`-object.

    - #### getSecond

          public int getSecond()

      Returns:
        the the second-of-minute (from 0 to 59) of this `Time`-object.

    - #### getMillisecond

          public int getMillisecond()

      Returns:
        the millisecond-of-second, from 0 to 999

    - #### getNano

          public int getNano()

      Returns:
        the nano-of-second (from 0 to 999_999_999) of this `Time`-object.

    - #### compareTo

          public int compareTo(DateTime other)

      Compares an object with another `DateTime`-object.
      Returns:
        -1, if `other` is not `null` and `value` is `null`,
        0, if `other` is `null` and `value` is `null`,
        1, if `other` is `null` and `value` is not `null`,
        `value.compareTo(other.value)`, otherwise.

    - #### compareTo

          public int compareTo(Date other)

      Compares an object with another `Date` object. Comparation is made only on an intersected set of attributes for `Date` and `DateTime`.
      Parameters:
        `other` - An other comparing object
      Returns:
        A standard comparing return value

    - #### add

          public DateTime add(long amountToAdd,
                              DateTime.Unit unit)

      Changes a current value of an object for `amountToAdd` units of `unit`
      Parameters:
        `amountToAdd` - quantity of `unit` to be added (or subtracted, if `amountToAdd` is negative} to a current object.
        `unit` - Chrono-unit of measure
      Returns:
        A reference to a current `DateTime`-object (in order to enable method-chaining)

    - #### toJavaUtilDate

          public java.util.Date toJavaUtilDate()

      Converts an object to `Date`.
      Returns:
        `Date` value of an object.

    - #### toDate

          public Date toDate()

      Returns:
        A `Date` part of an object.

    - #### toTime

          public Time toTime()

      Returns:
        A `Time` part of an object.

    - #### toLocalDateTime

          public java.time.LocalDateTime toLocalDateTime()

      Converts an object to `LocalDateTime`.
      Returns:
        `LocalDateTime` value of an object.

    - #### toFormattedString

          public java.lang.String toFormattedString(java.time.format.DateTimeFormatter formatter)

      Method which formats a date using `formatter`. At this point, `formatter` can not be `null`.
      Parameters:
        `formatter` - Non-`null` `DateTimeFormatter`
      Returns:
        Formatted date, if `value` is not `null`
        `FORMATTED_NULL_DATE_TIME`, otherwise

    - #### toString

          public java.lang.String toString()

      Converts to `String`, using `DEFAULT_FORMATTER`.
      Overrides:
        `toString` in class `java.lang.Object`
      Returns:
        DateTime presented as a formatted string

    - #### toString

          public java.lang.String toString(java.time.format.DateTimeFormatter formatter)

      Converts to `String`, using `formatter`. If `formatter` is `null`, then a standard `toString()` is used.
      Parameters:
        `formatter` - A format to be used when formatting a datetime
      Returns:
        Formatted datetime

    - #### toString

          public java.lang.String toString(java.util.Locale locale)

      Converts to `String`, using `locale`. If `locale` is `null`, then a standard `DEFAULT_LOCALE` is used.
      Parameters:
        `locale` - A locale to be used when formatting a datetime
      Returns:
        Formatted datetime

    - #### toString

          public java.lang.String toString(java.lang.String formatDescription)

      Converts to `String`, using a `DateTimeFormatter` defined by `formatDescription`.
      Parameters:
        `formatDescription` - A String-definition of a `DateTimeFormatter` to be used when formatting a date
      Returns:
        Formatted date

    - #### toString

          public static java.lang.String toString(DateTime dateTime,
                                                  java.util.Locale locale)

      Converts `dateTime` to `String`, using `locale`, following all other rules of formatting.
      Parameters:
        `dateTime` - A `DateTime`-object to be converted
        `locale` - A locale to be used when formatting a `dateTime`.
      Returns:
        Formatted dateTime
      See Also:
        `toString(Locale locale)`

    - #### toString

          public static java.lang.String toString(DateTime dateTime,
                                                  java.lang.String formatDescription)

      Converts `dateTime` to `String`, using `formatDescription`, following all other rules of formatting.
      Parameters:
        `dateTime` - A `DateTime`-object to be converted
        `formatDescription` - A String-definition of a `DateTimeFormatter` to be used when formatting a `dateTime`.
      Returns:
        Formatted dateTime
      See Also:
        `toString(String formatDescription)`

    - #### toString

          public static java.lang.String toString(DateTime dateTime,
                                                  java.time.format.DateTimeFormatter formatter)

      Converts `dateTime` to `String`, using `formatter`, following all other rules of formatting.
      Parameters:
        `dateTime` - A `DateTime`-object to be converted
        `formatter` - A format to be used when formatting a `dateTime`.
      Returns:
        Formatted dateTime
      See Also:
        `toString(DateTimeFormatter formatter)`

    - #### hashCode

          public int hashCode()

      Hashcode of an object.
      Hashcode of an object will be a hashcode of its value-container object `value`
      Overrides:
        `hashCode` in class `java.lang.Object`

    - #### equals

          public boolean equals(java.lang.Object other)

      Compares an object to another `DateTime` object. Two `DateTime` objects will be treated equal, if their value-container objects `value` are equal.
      Overrides:
        `equals` in class `java.lang.Object`
      Returns:
        `true`, if objects are equal,
        `false`, otherwise.

    - #### isSameDateAs

          public boolean isSameDateAs(Date otherDate)

      Compares an object to another `Date`-object. The method name is INTENTIONALLY chosen NOT TO BE `equals` in order to prevent a possible mix-up.
      `Date` and `DateTime` will be treated as "of same date" if they are equal on year/month/dayOfMonth level
      Parameters:
        `otherDate` - The other object
      Returns:
        `true`, if objects are equal on an intersected set of attributes
        `false`, otherwise.