Class Date

java.lang.Object
ch.ivyteam.ivy.scripting.objects.Date
All Implemented Interfaces:
IIvyDataObject, Serializable, Cloneable, Comparable<Date>

public final class Date extends Object implements IIvyDataObject, Comparable<Date>
Ivy Date objects have a year, a month and a day, but no day-time.
See Also:
API:
This is a public API.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Date
    An invalid date object.
    static final Date
    An uninitialized date object.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new Date object representing the actual day.
    Date(int _year, int _month, int _day)
    Creates a new date object.
    Date(String literal)
    Parses a Date literal and creates a new corresponding Date object.
    Date(Date _date)
    Creates a new date object.
    Creates a new date object.
  • Method Summary

    Modifier and Type
    Method
    Description
    add(Duration duration)
    Adds a duration to this date.
    Creates a clone of this object.
    int
    compareTo(Date otherDate)
    Compares two dates.
    boolean
    equals(Object anotherDate)
    Test two objects for equality.
    Formats this Date with the default format.
    The default format is defined in the configuration under Formats > Date > default.
    format(String formatName)
    Formats this Date with the given format config.
    int
    Returns the day of the date.
    int
    Returns the day of the week for this date.
    Calculates the duration from the current date to actual date instance.
    int
    Returns the month of the date.
    int
    Returns the year of the date.
    int
    A hash code.
    minus(Date date)
    Returns a normalized Duration representing the difference between this Date and the argument.
    minus(Duration duration)
    Subtracts a duration to this date.
    Returns a java.util.Calendar object corresponding to this Date object.
    Returns a java.util.Date object corresponding to this Date object.
    long
    Converts this date to a number; this is the number of second of this date after 1970-01-01 00:00:00.
    Returns the date as String in the ISO-8601 format (yyyy-mm-dd).
  • Field Details

    • UNINITIALIZED_DATE

      public static final Date UNINITIALIZED_DATE
      An uninitialized date object.
      API:
      This public API is available in Java.
    • INVALID

      public static final Date INVALID
      An invalid date object. Used by the widget validation
      API:
      This public API is available in Java.
  • Constructor Details

    • Date

      public Date()
      Creates a new Date object representing the actual day.
      API:
      This public API is available in Java.
    • Date

      public Date(int _year, int _month, int _day)
      Creates a new date object.
      Parameters:
      _year - The year of the date.
      _month - The month of the date. 1=January, 2=February, .. 11=November, 12=December
      _day - The day of the date. 1..28, 29, 30, 31 depending on month
      API:
      This public API is available in Java.
    • Date

      public Date(String literal)
      Parses a Date literal and creates a new corresponding Date object. If the format of the argument is not correct, an uninitialized Object is created.
      Parameters:
      literal - A date literal in the format yyyy-mm-dd or dd.mm.yyyy.
      Throws:
      IllegalArgumentException - if the argument has an illegal format.
      API:
      This public API is available in Java.
    • Date

      public Date(GregorianCalendar _calendar)
      Creates a new date object.
      Parameters:
      _calendar - The calendar for the date.
      API:
      This public API is available in Java.
    • Date

      public Date(Date _date)
      Creates a new date object.
      Parameters:
      _date - a java date object
      API:
      This public API is available in Java.
  • Method Details

    • getYear

      public int getYear()
      Returns the year of the date.
      Returns:
      The year of the date.
      API:
      This public API is available in Java.
    • getMonth

      public int getMonth()
      Returns the month of the date.
      Returns:
      The month of the date. 1=January, 2=February .. 11=November, 12=December
      API:
      This public API is available in Java.
    • getDay

      public int getDay()
      Returns the day of the date.
      Returns:
      The day of the date. 1..28, 29, 30, 31 depending on month
      API:
      This public API is available in Java.
    • getDayOfWeek

      public int getDayOfWeek()
      Returns the day of the week for this date.
      Returns:
      The day of the week for this date. 1=Sunday, 2=Monday, .. 6=Friday, 7=Saturday
      API:
      This public API is available in Java.
    • add

      public Date add(Duration duration)
      Adds a duration to this date.
      Parameters:
      duration - A duration.
      Returns:
      A new date objact translated by the duration.
      API:
      This public API is available in Java.
    • minus

      public Date minus(Duration duration)
      Subtracts a duration to this date.
      Parameters:
      duration - A duration.
      Returns:
      A new date objact translated by the duration.
      API:
      This public API is available in Java.
    • minus

      public Duration minus(Date date)
      Returns a normalized Duration representing the difference between this Date and the argument. The result Duration has no year or month part.
      Parameters:
      date -
      Returns:
      a normalized Duration.
      API:
      This public API is available in Java.
    • getDurationFromNow

      public Duration getDurationFromNow()
      Calculates the duration from the current date to actual date instance.
      Returns:
      Duration from the current date to actual date instance.
      API:
      This public API is available in Java.
    • toNumber

      public long toNumber()
      Converts this date to a number; this is the number of second of this date after 1970-01-01 00:00:00.
      Returns:
      Number of seconds after 1970-01-01 00:00:00.
      API:
      This public API is available in Java.
    • compareTo

      public int compareTo(Date otherDate)
      Compares two dates.
      Parameters:
      otherDate - Some date.
      Returns:
      -1 if the receiver is before the argument, 0 if the receiver is equal to the argument 1 if the receiver is after the argument.
      API:
      This public API is available in Java.
    • toString

      public String toString()
      Returns the date as String in the ISO-8601 format (yyyy-mm-dd).
      Returns:
      The date as String in the ISO-8601 format (yyyy-mm-dd).
      API:
      This public API is available in Java.
    • toJavaDate

      public Date toJavaDate()
      Returns a java.util.Date object corresponding to this Date object.

      Note: under ivy script environment a Date object is automatically converted to DateTime.

      Returns:
      A java.util.Date object corresponding to this Date object.
      API:
      This public API is available in Java.
    • toCalendar

      public Calendar toCalendar()
      Returns a java.util.Calendar object corresponding to this Date object.
      Returns:
      A java.util.Calendar object corresponding to this Date object.
      API:
      This public API is available in Java.
    • format

      public String format()
      Formats this Date with the default format.
      The default format is defined in the configuration under Formats > Date > default.
      Returns:
      formatted String
      API:
      This public API is available in Java.
    • format

      public String format(String formatName)
      Formats this Date with the given format config.
      Parameters:
      formatName - Name of a configuration under Formats > Date.
      E.g. "default", "medium", "short" etc.
      Returns:
      formatted String
      API:
      This public API is available in Java.
    • equals

      public boolean equals(Object anotherDate)
      Test two objects for equality.
      Parameters:
      anotherDate - Some object.
      Returns:
      true if the receiver is equal to the argument.
      API:
      This public API is available in Java.
    • hashCode

      public int hashCode()
      A hash code.
      Returns:
      A hash code.
      API:
      This public API is available in Java.
    • clone

      public Date clone()
      Creates a clone of this object.
      Specified by:
      clone in interface IIvyDataObject
      Returns:
      A shallow clone.
      API:
      This public API is available in Java.