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.
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(datetime1: String, datetime2: String): String
Returns:
1
if datetime1
is after datetime2
-1
if datetime1
is before datetime2
0
if datetime1
and datetime2
are the same
Example
Resultof¶
of(parts: Object[Number|String]): String
Returns the String
representation of the date and time given in parts
, an Object
of the form:
{
year: Number, month: Number, day: Number,
hour: Number, minute: Number, second: Number,
offset: String
}
where all elements are optional.
Example
Resultbetween¶
between(datetime1: String, datetime2: 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, format: String): String
Returns the given datetime
formatted in the requested format
.
Example
ResultisLeapYear¶
isLeapYear(datetime: String): String
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
.
Example
Resultnow¶
now(): String
Returns the current datetime.
Example
Resultparse¶
parse(datetime: String|Number, format: 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
.
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, format: 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,
hour: Number, minute: Number, second: Number, nanosecond: Number,
offset: String
}
Example
Resulttoday¶
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