Class DateValue

java.lang.Object
com.aquima.interactions.foundation.types.AbstractValue
com.aquima.interactions.foundation.types.DateValue
All Implemented Interfaces:
IConvertable, IPrimitiveValue, ISingleValue, IValue, Serializable, Comparable<Object>
Direct Known Subclasses:
AttributeDateValue, DateTimeValue

public class DateValue extends AbstractValue

This primitive class holds the information about a single date value.

This class should not contain any time data, use DateTimeValue for a date with a time component.

Since:
5.0
Author:
O. Kerpershoek
See Also:
  • Field Details

    • UNKNOWN

      public static final DateValue UNKNOWN
      This member defines the UNKNOWN value for the date type.
    • MILLISECONDS_PER_SECOND

      public static final long MILLISECONDS_PER_SECOND
      This member defines the number of milliseconds in a second.
      See Also:
    • MILLISECONDS_PER_MINUTE

      public static final long MILLISECONDS_PER_MINUTE
      This member defines the number of milliseconds in a minute.
      See Also:
    • MILLISECONDS_PER_HOUR

      public static final long MILLISECONDS_PER_HOUR
      This member defines the number of milliseconds in an hour.
      See Also:
    • MILLISECONDS_PER_DAY

      public static final long MILLISECONDS_PER_DAY
      This member defines the number of milliseconds in a (SI) day.
      See Also:
    • ISO8601_CUSTOM_LOCAL_DATE_TIME

      protected static final DateTimeFormatter ISO8601_CUSTOM_LOCAL_DATE_TIME
      Date time formatter used by DateValue. ISO-8601 local date and time without milliseconds and nanoseconds.
  • Constructor Details

    • DateValue

      protected DateValue()
    • DateValue

      public DateValue(DateValue other)
      Copy constructor.
      Parameters:
      other - DateValue to copy.
    • DateValue

      protected DateValue(DateValue other, boolean includeTime)
    • DateValue

      public DateValue(int y, int m, int d)
      Construct a DateValue, with year months and day.
      • Month 1 is January, day 1 is the first day of the month specified.
      • Dates are always interpreted using the (proleptic) Gregorian calendar rules. Before 17.0, dates before 1582-10-15 where interpreted using the Julian calendar rules
      • The system default timezone is used
      Parameters:
      y - The year of the date (1 through 9999).
      m - The month of the date (a value from 1 up to 12).
      d - The day of the date (a value from 1 up to 31).
    • DateValue

      protected DateValue(int y, int m, int d, int hour, int minute, int second, int millis)
    • DateValue

      protected DateValue(ZonedDateTime zdt, boolean includeTime)
      Construct a DateValue based on a ZonedDateTime. The year of the ZonedDateTime must be in the range 1 through 9999. Note that the given ZonedDateTime will be converted to the system default timezone.
      Parameters:
      zdt - The ZonedDateTime to construct this DateValue with, may be null.
      includeTime - When true zdt is used as is, when false the time part is set to 00:00:00.
    • DateValue

      public DateValue(Date date)
      Construct a DateValue based on a Date. The year of the Date must be in the range 1 through 9999. The system default timezone is used
      Parameters:
      date - The Date to construct this DateValue with.
    • DateValue

      public DateValue(IMultilingualText displayValue, Date date)
      Construct a DateValue based on a Date and with a display text. The year of the Date must be in the range 1 through 9999. The system default timezone is used
      Parameters:
      displayValue - Text object containing the display value that should be used.
      date - The Date to construct this DateValue with.
    • DateValue

      public DateValue(String typeName, IMultilingualText displayValue, Date date)
      Construct a DateValue based on a Date as a domain value. The year of the Date must be in the range 1 through 9999. The system default timezone is used
      Parameters:
      typeName - The name of the domain the value belongs to.
      displayValue - Text object containing the display value that should be used.
      date - The Date to construct this DateValue with.
    • DateValue

      protected DateValue(String typeName, IMultilingualText displayValue, Date date, boolean includeTime)
  • Method Details

    • valueOf

      public static DateValue valueOf(Object obj)

      Parse an object and returns its DateValue.

      This method currently returns the date with a time component. Also, when the object provided contains a time component (except when it is a String), this will be parsed. We intend to change this behavior in release 15.0, by no longer parsing the time component and also not returning it. If you need a date with time component, use DateTimeValue.valueOf(Object) instead.

      • Date Strings are always interpreted using the (proleptic) Gregorian calendar rules. Before 17.0, date Strings before 1582-10-15 where interpreted using the Julian calendar rules
      • The system default timezone is used
      Parameters:
      obj - The object to parse.
      Returns:
      The DateValue representation of the object, never null, but can be unknown.
      Throws:
      ConversionException - Is thrown when parsing fails.
    • parseDate

      public static Date parseDate(Object obj)
      This method tries to create a Date from the provided object. If the object is a String representation of a Date, it will be parsed. It expects a String format with year-month-day only, so without time component.
      • Date Strings are always interpreted using the (proleptic) Gregorian calendar rules. Before 17.0, date Strings before 1582-10-15 where interpreted using the Julian calendar rules
      • The system default timezone is used
      Parameters:
      obj - The object to parse into a Date.
      Returns:
      Date parsed from the provided object.
      Throws:
      ConversionException - when the String representation of the object cannot be parsed according to the applicable format.
    • createToday

      public static DateValue createToday()
      This method can be used to create a DateValue for the current date. The current time is not included in the resulting date value.
      Returns:
      DateValue for today.
    • forType

      public IPrimitiveValue forType(String typeName, IMultilingualText displayValue)
      Description copied from interface: IPrimitiveValue
      This method adds the type and display information to the value, and returns the value with this added information. The method will not change the state of the value the method is invoked on, but it will return a copy of the current value with the added information.
      Specified by:
      forType in interface IPrimitiveValue
      Specified by:
      forType in class AbstractValue
      Parameters:
      typeName - The type of the value.
      displayValue - Multilingual text containing display values.
      Returns:
      The value with the added information.
    • contains

      public boolean contains(Object objValue)
      Description copied from interface: IValue
      This method returns a boolean indicating if the object passed to this method is entirely part of this value. This method will thus also return true when the object passed is equal to this value, but the method will return false when only part (or none) of the object is represented by this value. Note that for value types that are singular in nature (for instance, implementations of ISingleValue) the operation of this method is limited to an equality check.
      Specified by:
      contains in interface IValue
      Specified by:
      contains in class AbstractValue
      Parameters:
      objValue - Object for which should be checked if it is entirely part of this value.
      Returns:
      boolean indicating if the object passed is entirely part of this value.
    • getDataType

      public DataType getDataType()
      Description copied from interface: IValue
      This method returns the data type of the value.
      Specified by:
      getDataType in interface IValue
      Specified by:
      getDataType in class AbstractValue
      Returns:
      The data type of the value.
    • isUnknown

      public boolean isUnknown()
      Description copied from interface: IValue
      This method returns a boolean indicating if the value is unknown.
      Specified by:
      isUnknown in interface IValue
      Specified by:
      isUnknown in class AbstractValue
      Returns:
      boolean indicating if the value is unknown.
    • compareSimple

      protected int compareSimple(Object obj)
      Specified by:
      compareSimple in class AbstractValue
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class AbstractValue
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class AbstractValue
    • longValue

      public long longValue()
      Description copied from interface: IConvertable
      This method converts the internal value to a long primitive.
      Specified by:
      longValue in interface IConvertable
      Specified by:
      longValue in class AbstractValue
      Returns:
      Long primitive of the internal value.
    • getValue

      public Object getValue()
      Description copied from interface: IConvertable
      This method returns the internal object of this instance without any conversion.
      Specified by:
      getValue in interface IConvertable
      Specified by:
      getValue in class AbstractValue
      Returns:
      The internal Object of this attribute value.
    • booleanValue

      public boolean booleanValue()
      Description copied from interface: IConvertable
      This method converts the internal value to a boolean primitive.
      Specified by:
      booleanValue in interface IConvertable
      Specified by:
      booleanValue in class AbstractValue
      Returns:
      Boolean primitive of the internal value.
    • dateValue

      public Date dateValue()
      Description copied from interface: IConvertable
      This method converts the internal value to a date object.
      Specified by:
      dateValue in interface IConvertable
      Specified by:
      dateValue in class AbstractValue
      Returns:
      Date object of the internal value.
    • doubleValue

      public double doubleValue()
      Description copied from interface: IConvertable
      This method converts the internal value to a double primitive.
      Specified by:
      doubleValue in interface IConvertable
      Specified by:
      doubleValue in class AbstractValue
      Returns:
      Double primitive of the internal value.
    • integerValue

      public int integerValue()
      Description copied from interface: IConvertable
      This method converts the internal value to an integer primitive.
      Specified by:
      integerValue in interface IConvertable
      Specified by:
      integerValue in class AbstractValue
      Returns:
      Integer primitive of the internal value.
    • getLeanDateFormat

      @Deprecated(since="17.0") public DateFormat getLeanDateFormat()
      Deprecated.
      This method is deprecated. Use toString() or toISO8601() for formatting. Use parseDate(Object) or DateTimeValue.parseDateTime(Object) for parsing. Alternatively use DateTimeFormatter to format/parse your own dates
      Returns:
      An Aquima DateFormat for ISO-8601 local date and time without milliseconds and nanoseconds
    • stringValue

      public String stringValue()
      Format this DateValue to a String in the format 'yyyy-MM-dd'.
      • Dates are always formatted using the (proleptic) Gregorian calendar rules. Before 17.0, dates before 1582-10-15 where formatted using the Julian calendar rules.
      • The system default timezone is used.
      Specified by:
      stringValue in interface IConvertable
      Specified by:
      stringValue in class AbstractValue
      Returns:
      A String representation of this DateValue
    • toISO8601

      public String toISO8601()
      Format this DateValue (or DateTimeValue) to an ISO-8601 local date and time without milliseconds and nanoseconds (format 'yyyy-MM-ddTHH:mm:ss').
      • Dates are always formatted using the (proleptic) Gregorian calendar rules. Before 17.0, dates before 1582-10-15 where formatted using the Julian calendar rules.
      • The system default timezone is used.
      Returns:
      Formatted ISO-8601 local date and time
    • hoursBefore

      public IntegerValue hoursBefore(DateValue other)

      This method returns the number of hours the other date value is before this.

      When this date value is after the other date value, a negative integer value is returned.

      When this or the other date value is unknown an unknown integer value is returned.

      Parameters:
      other - The DateValue to compare to, mandatory.
      Returns:
      The number of hours this date value is before the other date value.
    • minutesBefore

      public IntegerValue minutesBefore(DateValue other)

      This method returns the number of minutes the other date value is before this.

      When this date value is after the other date value, a negative integer value is returned.

      When this or the other date value is unknown an unknown integer value is returned.

      Parameters:
      other - The DateValue to compare to, mandatory.
      Returns:
      The number of minutes this date value is before the other date value.
    • secondsBefore

      public IntegerValue secondsBefore(DateValue other)

      This method returns the number of seconds the other date value is before this.

      When this date value is after the other date value, a negative integer value is returned.

      When this or the other date value is unknown an unknown integer value is returned.

      Parameters:
      other - The DateValue to compare to, mandatory.
      Returns:
      The number of seconds this date value is before the other date value.
    • millisBefore

      public IntegerValue millisBefore(DateValue other)

      This method returns the number of milliseconds the other date value is before this.

      When this date value is after the other date value, a negative integer value is returned.

      When this or the other date value is unknown an unknown integer value is returned.

      Parameters:
      other - The DateValue to compare to, mandatory.
      Returns:
      The number of milliseconds this date value is before the other date value.
    • daysBefore

      public IntegerValue daysBefore(DateValue other)

      This method returns the number of days the other date value is before this.

      When this date value is after the other date value, a negative integer value is returned.

      When this or the other date value is unknown an unknown integer value is returned.

      Note that time components are ignored for both date values. For example:

       new TimestampValue( 2009, 1, 1, 23, 30, 0, 0 ).daysBefore( new DateValue(2009, 1, 2 ) ) will result in 1
       
      Parameters:
      other - The DateValue to compare to, mandatory.
      Returns:
      The number of days this date value is before the other date value.
    • workingDaysBetween

      public IntegerValue workingDaysBetween(DateValue other)
      This method passes the default working days (Mo - Tu - We - Th - Fr) to the workingDaysBetween(DateValue, ListValue) method.
      Parameters:
      other - the other date value
      Returns:
      working days between the two dates
    • workingDaysBetween

      public IntegerValue workingDaysBetween(DateValue other, ListValue workingDays)
      This method returns the number of full working days between this date value and another date value. Time components are ignored. The order of this date value and the other does not matter.
      Parameters:
      other - the date value to compare to
      workingDays - a list with the working days, as defined by getDayOfWeek() method.
      Returns:
      a positive integer indicating the number of full working days
    • weeksBefore

      public IntegerValue weeksBefore(DateValue other)

      This method returns the number of weeks the other date value is before this.

      When this date value is after the other date value, a negative integer value is returned.

      When this or the other date value is unknown an unknown integer value is returned.

      Note that time components are ignored for both date values. For example:

       new TimestampValue( 2009, 1, 1, 23, 30, 0, 0 ).weeksBefore( new DateValue(2009, 1, 8 ) ) will result in 1
       
      Parameters:
      other - The DateValue to compare to, mandatory.
      Returns:
      The number of weeks this date value is before the other date value.
    • monthsBefore

      public IntegerValue monthsBefore(DateValue other)

      This method returns the number of months the other date value is before this.

      When this date value is after the other date value, a negative integer value is returned.

      When this or the other date value is unknown an unknown integer value is returned.

      Note that time components are ignored for both date values. For example:

       new TimestampValue( 2009, 1, 1, 23, 30, 0, 0 ).monthsBefore( new DateValue(2009, 2, 1 ) ) will result in 1
       
      Parameters:
      other - The DateValue to compare to, mandatory.
      Returns:
      The number of months this date value is before the other date value.
    • yearsBefore

      public IntegerValue yearsBefore(DateValue other)

      This method returns the number of years the other date value is before this.

      When this date value is after the other date value, a negative integer value is returned.

      When this or the other date value is unknown an unknown integer value is returned.

      Note that time components are ignored for both date values. For example:

       new TimestampValue( 2009, 1, 1, 23, 30, 0, 0 ).yearsBefore( new DateValue(2010, 1, 1 ) ) will result in 1
       
      Parameters:
      other - The DateValue to compare to, mandatory.
      Returns:
      The number of years this date value is before the other date value.
    • withHours

      public DateTimeValue withHours(int hours)
    • withMinutes

      public DateTimeValue withMinutes(int minutes)
    • withSeconds

      public DateTimeValue withSeconds(int seconds)
    • withMilliseconds

      public DateTimeValue withMilliseconds(int milliSeconds)
    • createFor

      protected DateValue createFor(ZonedDateTime zdt)
    • withDays

      public DateValue withDays(int days)
    • withWeeks

      public DateValue withWeeks(int weeks)
    • withMonths

      public DateValue withMonths(int months)
    • withYears

      public DateValue withYears(int years)
    • getDayOfWeek

      public IntegerValue getDayOfWeek()
      Returns:
      The day of the week, sunday (1) to saturday (7)
    • getDayOfMonth

      public IntegerValue getDayOfMonth()
    • getYear

      public IntegerValue getYear()
    • getMonthOfYear

      public IntegerValue getMonthOfYear()
      This method returns the month of the current date value. The number of the month ranges from 1 to 12, or unknown when the date value represents an unknown value.
      Returns:
      The number of the month of the date value.
    • getWeekOfYear

      public IntegerValue getWeekOfYear()
      This method returns the week number of the current date value. The number ranges from 1 to 53. The first day of the week is Monday and the first week of the year is the week with 4 days or more in the starting year, following the ISO 8601 Week date specification).
      Returns:
      the number of the week of the year for this date value
    • toDateTimeValue

      public DateTimeValue toDateTimeValue()
    • toDateValue

      public DateValue toDateValue()
    • hourOfDay

      protected IntegerValue hourOfDay()
    • minute

      protected IntegerValue minute()
    • second

      protected IntegerValue second()
    • millisecond

      protected IntegerValue millisecond()
    • now

      protected static DateTimeValue now()
    • duplicate

      public IValue duplicate()
      Description copied from interface: IValue
      This method returns a deep copy of the value.
      Specified by:
      duplicate in interface IValue
      Specified by:
      duplicate in class AbstractValue
      Returns:
      A deep clone.
    • finalize

      protected final void finalize()
      Overrides:
      finalize in class Object