xtr.datetime¶
The datetime module leverages the ISO-8601 offset date-time format for representing and manipulating date and time, and the ISO-8601 duration format for temporal amounts. The ISO format is the recommendation of the IETF through RFC 3339: Date and Time on the Internet.
Hint
Users that need to operate on other date and time formats can use the parse function to convert it to the supported format, operate on the result, and optionally output it to any other format with the format function.
atBeginningOfDay¶
atBeginningOfDay(datetime: String): String
Returns the given datetime at midnight.
Example
ResultatBeginningOfHour¶
atBeginningOfHour(datetime: String): String
Returns the given datetime with the minutes and seconds set to zero.
Example
ResultatBeginningOfMonth¶
atBeginningOfMonth(datetime: String): String
Returns the given datetime with the day set to first of the month, and the time set to midnight.
Example
ResultatBeginningOfWeek¶
atBeginningOfWeek(datetime: String): String
Returns the given datetime with the day set to first of the current week, and the time set to midnight. The week is taken to start on Sunday.
Example
ResultatBeginningOfYear¶
atBeginningOfYear(datetime: String): String
Returns the given datetime with the day/month set to January 1st, and the time set to midnight.
Example
ResultinOffset¶
inOffset(datetime: String, offset: String): String
Returns the given datetime in the given timezone offset, changing the date and time as appropriate.
Example
Resultcompare¶
compare(datetime: String, datetwo: String): Number
Returns:
1 if datetime is after datetwo
-1 if datetime is before datetwo
0 if datetime and datetwo are the same
Example
Resultof¶
of(obj: Object[Number|String]): String
Returns the String representation of the date and time given in obj, an Object of the form:
{
year: Number, month: Number, day: Number,
hour: Number, minute: Number, second: Number,
nanosecond: Number, offset: String
}
where all elements are optional; keys outside this form are an error, except dayOfWeek, which is accepted and ignored so that of(toParts(x)) round-trips.
Example
Resultbetween¶
between(datetimeone: String, datetimetwo: String): String
Returns the ISO-8601 duration between datetime1 and datetime2.
Example
local date1 = '2019-09-20T18:53:41.425Z';
local date2 = '2019-09-14T18:53:41.425Z';
xtr.datetime.between(date1, date2)
format¶
format(datetime: String, outputFormat: String): String
Returns the given datetime formatted in the requested format.
Example
ResultisLeapYear¶
isLeapYear(datetime: String): Boolean
Returns a true if datetime is in a leap year, otherwise false.
Example
Resultminus¶
minus(datetime: String, duration: String): String
Returns the result of subtracting the specified ISO-8601 duration from the given datetime. Accepts any duration xtr.duration.of can produce, including time-only forms like 'PT2H'; a leading minus sign negates every part of the duration.
Example
Resultnow¶
now(): String
Returns the current datetime.
Example
Resultparse¶
parse(datetime: String|Number, inputFormat: String): String
Returns an ISO-8601 extended offset date-time from the given datetime using the specified format.
Example
ResultAdditionally, developers can parse Unix timestamps by passing 'unix' as the format.
Warning
Date strings without a time offset or a time zone identifier will be defaulted to UTC time. If more control is needed, developers may add append time zone information before parsing.
plus¶
plus(datetime: String, duration: String): String
Returns the result of adding the specified ISO-8601 duration to the given datetime. Accepts any duration xtr.duration.of can produce, including time-only forms like 'PT2H'; a leading minus sign negates every part of the duration.
Example
ResulttoLocalDate¶
toLocalDate(datetime: String): String
Returns the given datetime without time or offset.
Example
ResulttoLocalDateTime¶
toLocalDateTime(datetime: String): String
Returns the given datetime without an offset.
Example
ResulttoLocalTime¶
toLocalTime(datetime: String): String
Returns the given datetime without date or offset.
Example
ResulttoParts¶
toParts(datetime: String): Object[Number|String]
Returns the constituent parts of the given datetime, as an Object of the form:
{
year: Number, month: Number, day: Number, dayOfWeek: Number,
hour: Number, minute: Number, second: Number, nanosecond: Number,
offset: String
}
day is the day of the month, so that of(toParts(x)) round-trips — of reads the day key as the day of the month. The day of the week is dayOfWeek, 1 (Monday) through 7 (Sunday).
Example
Result{
year: 2019, month: 7, day: 10, dayOfWeek: 3,
hour: 21, minute: 0, second: 0, nanosecond: 0,
offset: 'Z'
}
today¶
today(): String
Returns the current day at midnight.
Example
Result
tomorrow¶
tomorrow(): String
Returns the next day at midnight.
Example
Result
yesterday¶
yesterday(): String
Returns the previous day at midnight.
Example
Result