Package ch.ivyteam.ivy.scripting.objects
Class DateTime
- java.lang.Object
-
- ch.ivyteam.ivy.scripting.objects.DateTime
-
- All Implemented Interfaces:
IIvyDataObject,Serializable,Cloneable,Comparable<DateTime>
public final class DateTime extends Object implements IIvyDataObject, Comparable<DateTime>
A Timestamp object.- See Also:
- Serialized Form
- API:
- This is a public API.
-
-
Field Summary
Fields Modifier and Type Field Description static DateTimeINVALIDAn invalid datetime object.static DateTimeUNINITIALIZED_DATE_TIMEAn uninitialized date object
-
Constructor Summary
Constructors Constructor Description DateTime()Creates a new DateTime object representing the actual day.DateTime(int _year, int _month, int _day, int _hours, int _minutes, int _seconds)Creates a new date object.DateTime(Date date, Time time)Creates a new DateTime object from a date and a day-time.DateTime(String literal)Parses a DateTime literal and creates a new corresponding Date object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DateTimeadd(Duration duration)Adds a duration to this date.DateTimeclone()Creates a clone of this object.intcompareTo(DateTime otherDateTime)Compares two DataTime objects.booleanequals(Object anotherDate)Test two objects for euality.Stringformat()Formats thisDateTimewith the default format.
The default format is defined in the configuration underFormats > DateTime > default.Stringformat(String formatName)Formats thisDateTimewith the given format config.Stringformat(String dateFormatName, String timeFormatName)Formats thisDateTimewith the given format configurations for the date and time part.DategetDate()intgetDay()Returns the day of this DateTime object.intgetDayOfWeek()Returns the day of the week for this DateTime object.DurationgetDurationFromNow()Calculates the duration from the current dateTime to actual dateTime instance.intgetHours()Returns the hours for this DateTime object.intgetMinutes()Returns the minutes for this DateTime object.intgetMonth()Returns the month of this DateTime object.intgetSeconds()Returns the seconds for this DateTime object.TimegetTime()intgetYear()Returns the year of this DateTime object.inthashCode()A hashcode; the number of seconds after 1970-01-01.Durationminus(DateTime dateTime)Returns a normalized Duration representing the difference between this DateTime and the argument.DateTimeminus(Duration duration)Subtracts a duration to this date.DatetoIvyDate()longtoNumber()Converts this date to a number; this is the number of second of this date after 1970-01-01 00:00:00.StringtoString()Returns the date as String in the ISO-8601 format (yyyy-mm-dd hh:mm:ss).TimetoTime()
-
-
-
Field Detail
-
UNINITIALIZED_DATE_TIME
public static final DateTime UNINITIALIZED_DATE_TIME
An uninitialized date object- API:
- This public API is available in IvyScript and Java. It has the visibility EXPERT.
-
INVALID
public static final DateTime INVALID
An invalid datetime object. Used by the widget validation- API:
- This public API is available in IvyScript and Java. It has the visibility EXPERT.
-
-
Constructor Detail
-
DateTime
public DateTime()
Creates a new DateTime object representing the actual day.- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
DateTime
public DateTime(int _year, int _month, int _day, int _hours, int _minutes, int _seconds)Creates a new date object.- Parameters:
_year- The year of the DateTime object._month- The month of the DateTime object. 1=January, 2=February .. 11=November, 12=December_day- The day of the DateTime object. 1..28, 29, 30, 31 depending on month_hours- The hours of the DateTime object._minutes- The minutes of the DateTime object._seconds- The seconds of the DateTime object.- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
DateTime
public DateTime(Date date, Time time)
Creates a new DateTime object from a date and a day-time.- Parameters:
date-time-- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
DateTime
public DateTime(String literal)
Parses a DateTime literal and creates a new corresponding Date object.If the format of the argument is not correct, an
IllegalArgumentExceptionwill be thrown.- Parameters:
literal- A date literal in the format- yyyy-mm-dd hh:mm:ss or
- yyyy-mm-dd hh:mm or
- dd.mm.yyyy hh:mm:ss or
- dd.mm.yyyy hh:mm.
- Throws:
IllegalArgumentException- if the argument has an illegal format.- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
-
Method Detail
-
getDate
public Date getDate()
-
getTime
public Time getTime()
-
getYear
public int getYear()
Returns the year of this DateTime object.- Returns:
- The year of this DateTime object.
- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
getMonth
public int getMonth()
Returns the month of this DateTime object.- Returns:
- The month of this DateTime object. 1=January, 2=February .. 11=November, 12=December
- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
getDay
public int getDay()
Returns the day of this DateTime object.- Returns:
- The day of this DateTime object. 1..28, 29, 30, 31 depending on month
- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
getDayOfWeek
public int getDayOfWeek()
Returns the day of the week for this DateTime object.- Returns:
- The day of the week for this DateTime object. 1=Sunday, 2=Monday, .. 6=Friday, 7=Saturday
- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
getHours
public int getHours()
Returns the hours for this DateTime object.- Returns:
- The hours for this DateTime object.
- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
getMinutes
public int getMinutes()
Returns the minutes for this DateTime object.- Returns:
- The minutes for this DateTime object.
- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
getSeconds
public int getSeconds()
Returns the seconds for this DateTime object.- Returns:
- The seconds for this DateTime object.
- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
add
public DateTime add(Duration duration)
Adds a duration to this date.- Parameters:
duration- A duration.- Returns:
- A new date object translated by the duration.
- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
minus
public DateTime 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 IvyScript and Java. It has the visibility NOVICE.
-
minus
public Duration minus(DateTime dateTime)
Returns a normalized Duration representing the difference between this DateTime and the argument. The result Duration has no year or month part.- Parameters:
dateTime-- Returns:
- The difference between durations.
- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
getDurationFromNow
public Duration getDurationFromNow()
Calculates the duration from the current dateTime to actual dateTime instance.- Returns:
- Duration from the current dateTime to actual dateTime instance.
- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
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 IvyScript and Java. It has the visibility NOVICE.
-
compareTo
public int compareTo(DateTime otherDateTime)
Compares two DataTime objects.- Parameters:
otherDateTime- 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 IvyScript and Java. It has the visibility NOVICE.
-
toString
public String toString()
Returns the date as String in the ISO-8601 format (yyyy-mm-dd hh:mm:ss).- Returns:
- The date as String in the ISO-8601 format (yyyy-mm-dd).
- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
toIvyDate
public Date toIvyDate()
-
toTime
public Time toTime()
-
format
public String format()
Formats thisDateTimewith the default format.
The default format is defined in the configuration underFormats > DateTime > default.- Returns:
- formatted String
- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
format
public String format(String formatName)
Formats thisDateTimewith the given format config.- Parameters:
formatName- Name of a configuration underFormats > DateTime.
E.g. "default", "medium", "short" etc.- Returns:
- formatted String
- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
format
public String format(String dateFormatName, String timeFormatName)
Formats thisDateTimewith the given format configurations for the date and time part.- Parameters:
dateFormatName- Name of a configuration underFormats > Date.
E.g. "default", "medium", "short" etc.timeFormatName- Name of a configuration underFormats > Time.
E.g. "default", "medium", "short" etc.- Returns:
- formatted String
- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
equals
public boolean equals(Object anotherDate)
Test two objects for euality.- Parameters:
anotherDate- Some object.- Returns:
- true if the receiver is equal to the argument.
- API:
- This public API is available in IvyScript and Java. It has the visibility EXPERT.
-
hashCode
public int hashCode()
A hashcode; the number of seconds after 1970-01-01.- Returns:
- A hashcode.
- API:
- This public API is available in IvyScript and Java. It has the visibility EXPERT.
-
clone
public DateTime clone()
Creates a clone of this object.- Specified by:
clonein interfaceIIvyDataObject- Returns:
- A shallow clone.
- API:
- This public API is available in IvyScript and Java. It has the visibility EXPERT.
-
-