JSONata Expressions - jensrossbach/node-red-contrib-chronos GitHub Wiki
All flow nodes support JSONata expressions for advanced control over the output, repetition, delay, conditions and rules. These expressions support the JSONata built-in functions, the Node-RED function extensions and a couple of additional functions related to date and time calculation. There are some functions common to all nodes and other functions specific to certain nodes only. Some of below described functions overlap with functionality already provided by the $moment
function from the Node-RED extensions but the Chronos provided functions have the advantage that they match the functionality as known from the node's user interface and they respect the time zone setting from the node's assigned configuration as far as applicable.
There are also some common expression variables as described below available in all JSONata expressions. Additional node specific variables are documented on the corresponding pages of the nodes.
Common Variables
The common variables are described below.
$node
Contains the configured name of the node or an empty string in case no name has been set.
$config
Contains information about the associated configuration node. The variable is an object and has the following proerties:
Property | Type | Description |
---|---|---|
name |
String | The name of the assigned configuration node. |
latitude |
Number | The latitude configured in the assigned configuration node or null if the latitude is configured as global context variable. Use $getLatitude() in this case. |
longitude |
Number | The longitude configured in the assigned configuration node or null if the longitude is configured as global context variable. Use $getLongitude() in this case. |
timezone |
String | The time zone configured in the assigned configuration node or null if the time zone is configured as global context variable. Use $getTimeZone() in this case. |
locale |
String | The locale configured in the Node-RED instance or - if not specified - the locale of the OS running Node-RED. |
Common Functions
The common functions are described below.
$getLatitude()
Signature: $getLatitude()
Returns the latitude configured in the assigned configuration node. If the latitude is configured as global context variable, it is retrieved from that variable on-the-fly.
Return Value
The latitude as number between -90° and 90°.
$getLongitude()
Signature: $getLongitude()
Returns the longitude configured in the assigned configuration node. If the longitude is configured as global context variable, it is retrieved from that variable on-the-fly.
Return Value
The longitude as number between -180° and 180°.
$getTimeZone()
Signature: $getTimeZone()
Returns the time zone configured in the assigned configuration node. If the time zone is configured as global context variable, it is retrieved from that variable on-the-fly.
Return Value
The time zone as string containing a time zone identifier.
$millisecond()
Signature: $millisecond(ts)
Returns the millisecond portion of the provided timestamp ts
.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp, must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date and time (now), pass the result of the JSONata built-in function millis() as argument. |
Return Value
The return value is a number containing the elapsed milliseconds within the current second (0..999).
$second()
Signature: $second(ts)
Returns the second portion of the provided timestamp ts
.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp, must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date and time (now), pass the result of the JSONata built-in function millis() as argument. |
Return Value
The return value is a number containing the elapsed seconds within the current minute (0..59).
$minute()
Signature: $minute(ts)
Returns the minute portion of the provided timestamp ts
.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp, must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date and time (now), pass the result of the JSONata built-in function millis() as argument. |
Return Value
The return value is a number containing the elapsed minutes within the current hour (0..59).
$hour()
Signature: $hour(ts)
Returns the hour portion of the provided timestamp ts
.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp, must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date and time (now), pass the result of the JSONata built-in function millis() as argument. |
Return Value
The return value is a number containing the elapsed hours within the current day (0..23).
$day()
Signature: $day(ts)
Returns the day of the month portion of the provided timestamp ts
.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp, must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date and time (now), pass the result of the JSONata built-in function millis() as argument. |
Return Value
The return value is a number containing the day of the month (1..31).
$dayOfWeek()
Signature: $dayOfWeek(ts)
Returns the day of the week portion of the provided timestamp ts
.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp, must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date and time (now), pass the result of the JSONata built-in function millis() as argument. |
Return Value
The return value is a number containing the day of the week (1..7) according to the configured locale.
$dayOfYear()
Signature: $dayOfYear(ts)
Returns the day of the year portion of the provided timestamp ts
.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp, must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date and time (now), pass the result of the JSONata built-in function millis() as argument. |
Return Value
The return value is a number containing the day of the year (1..365).
$week()
Signature: $week(ts)
Returns the week number of the provided timestamp ts
.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp, must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date and time (now), pass the result of the JSONata built-in function millis() as argument. |
Return Value
The return value is a number containing the week of the year according to the configured locale (1..52).
$month()
Signature: $month(ts)
Returns the month portion of the provided timestamp ts
.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp, must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date and time (now), pass the result of the JSONata built-in function millis() as argument. |
Return Value
The return value is a number containing the month (1..12).
$quarter()
Signature: $quarter(ts)
Returns the quarter of the year portion of the provided timestamp ts
.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp, must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date and time (now), pass the result of the JSONata built-in function millis() as argument. |
Return Value
The return value is a number containing the quarter of the year (1..4).
$year()
Signature: $year(ts)
Returns the year portion of the provided timestamp ts
.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp, must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date and time (now), pass the result of the JSONata built-in function millis() as argument. |
Return Value
The return value is a number containing the year.
$time()
Signature: $time(ts, time, offset, random)
Returns the time according to the given time string or number at the date from the provided timestamp.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp for the date part, must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date (today), pass the result of the JSONata built-in function millis() as argument. |
time |
Number, String | yes | Time as number or string. In case of a string, the format must be the same as described in section Time Input. In case of a number, it must contain the number of milliseconds elapsed since midnight. |
offset |
Number | no | Offset to add to or subtract from the time; must be in minutes between -300 and +300. |
random |
Number | no | Offset randomization span with offset being the center; must be in minutes between 0 and 300. |
Return Value
The return value is a timstamp as number of milliseconds since the Unix epoch.
$sunTime()
Signature: $sunTime(ts, pos, offset, random)
Returns the sun time for the given sun position name at the date from the provided timestamp.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp for the date part; must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date (today), pass the result of the JSONata built-in function millis() as argument. |
pos |
String | yes | Name of the sun position; one of "nightEnd", "nauticalDawn", "dawn", "sunrise", "sunriseEnd", "goldenHourEnd", "solarNoon", "goldenHour", "sunsetStart", "sunset", "dusk", "nauticalDusk", "night" or "nadir". |
offset |
Number | no | Offset to add to or subtract from the time; must be in minutes between -300 and +300. |
random |
Number | no | Offset randomization span with offset being the center; must be in minutes between 0 and 300. |
Return Value
The return value is a timstamp as number of milliseconds since the Unix epoch.
$moonTime()
Signature: $moonTime(ts, pos, offset, random)
Returns the moon time for the given moon position name at the date from the provided timestamp.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp for the date part; must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date (today), pass the result of the JSONata built-in function millis() as argument. |
pos |
String | yes | Name of the moon position; one of "rise" or "set". |
offset |
Number | no | Offset to add to or subtract from the time; must be in minutes between -300 and +300. |
random |
Number | no | Offset randomization span with offset being the center; must be in minutes between 0 and 300. |
Return Value
The return value is a timstamp as number of milliseconds since the Unix epoch.
Time Switch/Filter Node Functions
The following functions are specific to the Time Switch and Time Filter node.
$isSame()
Signature: $isSame(ts, type, value, offset, random, precision)
Checks if the given timestamp is equal to the time specified by arguments type, value, offset, random and precision.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp; must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date and time (now), pass the result of the JSONata built-in function millis() as argument; for the configured base time, pass the variable $baseTime . |
type |
String | yes | The type of time; one of "time", "sun", "moon" or "custom", see also Time Input. |
value |
String | yes | The time value, whose content is depending on the type of time, see also Time Input. |
offset |
String | no | The offset to the time in minutes; must be between -300 und +300. |
random |
Number | no | Offset randomization span with offset being the center; must be in minutes between 0 and 300. |
precision |
String | no | The precision for comparison; one of "millisecond", "second", "minute", "hour", "day", "month" or "year". |
Return Value
true
if timestamp is earlier, false
otherwise.
$isBefore()
Signature: $isBefore(ts, type, value, offset, random, precision)
Checks if the given timestamp is earlier than the time specified by arguments type, value, offset, random and precision.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp; must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date and time (now), pass the result of the JSONata built-in function millis() as argument; for the configured base time, pass the variable $baseTime . |
type |
String | yes | The type of time; one of "time", "sun", "moon" or "custom", see also Time Input. |
value |
String | yes | The time value, whose content is depending on the type of time, see also Time Input. |
offset |
String | no | The offset to the time in minutes; must be between -300 und +300. |
random |
Number | no | Offset randomization span with offset being the center; must be in minutes between 0 and 300. |
precision |
String | no | The precision for comparison; one of "millisecond", "second", "minute", "hour", "day", "month" or "year". |
Return Value
true
if timestamp is earlier, false
otherwise.
$isAfter()
Signature: $isAfter(ts, type, value, offset, random, precision)
Checks if the given timestamp is later than the time specified by arguments type, value, offset, random and precision.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp; must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date and time (now), pass the result of the JSONata built-in function millis() as argument; for the configured base time, pass the variable $baseTime . |
type |
String | yes | The type of time; one of "time", "sun", "moon" or "custom", see also Time Input. |
value |
String | yes | The time value, whose content is depending on the type of time, see also Time Input. |
offset |
String | no | The offset to the time in minutes; must be between -300 und +300. |
random |
Number | no | Offset randomization span with offset being the center; must be in minutes between 0 and 300. |
precision |
String | no | The precision for comparison; one of "millisecond", "second", "minute", "hour", "day", "month" or "year". |
Return Value
true
if timestamp is equal or later, false
otherwise.
$isBetween()
Signature: $isBetween(ts, type1, value1, offset1, random1, precision1, type2, value2, offset2, random2, precision2)
Checks if the given timestamp is equal to or later than the time specified by arguments type1, value1, offset1, random1 and precision1 and earlier than or equal to the time specified by arguments type2, value2, offset2, random2 and precision2.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp; must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date and time (now), pass the result of the JSONata built-in function millis() as argument; for the configured base time, pass the variable $baseTime . |
type1 |
String | yes | The type of first time; one of "time", "sun", "moon" or "custom", see also Time Input. |
value1 |
String | yes | The first time value, whose content is depending on the type of first time, see also Time Input. |
offset1 |
Number | yes | The offset to the first time in minutes; must be between -300 und +300. |
random1 |
Number | yes | Offset randomization span with offset1 being the center; must be in minutes between 0 and 300. |
precision1 |
String | yes | The precision for comparison; one of "millisecond", "second", "minute", "hour", "day", "month" or "year". |
type2 |
String | yes | The type of second time; one of "time", "sun", "moon" or "custom", see also Time Input. |
value2 |
String | yes | The second time value, whose content is depending on the type of second time, see also Time Input. |
offset2 |
Number | yes | The offset to the second time in minutes; must be between -300 und +300. |
random2 |
Number | yes | Offset randomization span with offset2 being the center; must be in minutes between 0 and 300. |
precision2 |
String | yes | The precision for comparison; one of "millisecond", "second", "minute", "hour", "day", "month" or "year". |
Return Value
true
if timestamp is equal to or later than the first and earlier than the second time, false
otherwise.
$isOutside()
Signature: $isOutside(ts, type1, value1, offset1, random1, precision1, type2, value2, offset2, random2, precision2)
Checks if the given timestamp is earlier than the time specified by arguments type1, value1, offset1, random1 and precision1 or later than the time specified by arguments type2, value2, offset2, random2 and precision2.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp; must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date and time (now), pass the result of the JSONata built-in function millis() as argument; for the configured base time, pass the variable $baseTime . |
type1 |
String | yes | The type of first time; one of "time", "sun", "moon" or "custom", see also Time Input. |
value1 |
String | yes | The first time value, whose content is depending on the type of first time, see also Time Input. |
offset1 |
Number | yes | The offset to the first time in minutes; must be between -300 und +300. |
random1 |
Number | yes | Offset randomization span with offset1 being the center; must be in minutes between 0 and 300. |
precision1 |
String | yes | The precision for comparison; one of "millisecond", "second", "minute", "hour", "day", "month" or "year". |
type2 |
String | yes | The type of second time; one of "time", "sun", "moon" or "custom", see also Time Input. |
value2 |
String | yes | The second time value, whose content is depending on the type of second time, see also Time Input. |
offset2 |
Number | yes | The offset to the second time in minutes; must be between -300 und +300. |
random2 |
Number | yes | Offset randomization span with offset2 being the center; must be in minutes between 0 and 300. |
precision2 |
String | yes | The precision for comparison; one of "millisecond", "second", "minute", "hour", "day", "month" or "year". |
Return Value
true
if timestamp is earlier than the first or later than the second time, false
otherwise.
$isFirstDay()
Signature: $isFirstDay(ts, day)
Checks if the day of the given timestamp matches the provided type of day and if it is the first one of the month.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp; must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date (today), pass the result of the JSONata built-in function millis() as argument; for the configured base time, pass the variable $baseTime . |
day |
String | no | Type of day; one of "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday", "day", "workday" or "weekend". If omitted, "day" (i.e., any day) is assumed. |
Return Value
true
for a match, false
otherwise.
$isSecondDay()
Signature: $isSecondDay(ts, day)
Checks if the day of the given timestamp matches the provided type of day and if it is the second one of the month.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp; must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date (today), pass the result of the JSONata built-in function millis() as argument; for the configured base time, pass the variable $baseTime . |
day |
String | no | Type of day; one of "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday" or "day". If omitted, "day" (i.e., any day) is assumed. |
Return Value
true
for a match, false
otherwise.
$isThirdDay()
Signature: $isThirdDay(ts, day)
Checks if the day of the given timestamp matches the provided type of day and if it is the third one of the month.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp; must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date (today), pass the result of the JSONata built-in function millis() as argument; for the configured base time, pass the variable $baseTime . |
day |
String | no | Type of day; one of "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday" or "day". If omitted, "day" (i.e., any day) is assumed. |
Return Value
true
for a match, false
otherwise.
$isFourthDay()
Signature: $isFourthDay(ts, day)
Checks if the day of the given timestamp matches the provided type of day and if it is the fourth one of the month.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp; must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date (today), pass the result of the JSONata built-in function millis() as argument; for the configured base time, pass the variable $baseTime . |
day |
String | no | Type of day; one of "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday" or "day". If omitted, "day" (i.e., any day) is assumed. |
Return Value
true
for a match, false
otherwise.
$isFifthDay()
Signature: $isFifthDay(ts, day)
Checks if the day of the given timestamp matches the provided type of day and if it is the fifth one of the month.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp; must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date (today), pass the result of the JSONata built-in function millis() as argument; for the configured base time, pass the variable $baseTime . |
day |
String | no | Type of day; one of "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday" or "day". If omitted, "day" (i.e., any day) is assumed. |
Return Value
true
for a match, false
otherwise.
$isLastDay()
Signature: $isLastDay(ts, day)
Checks if the day of the given timestamp matches the provided type of day and if it is the last one of the month.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp; must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date (today), pass the result of the JSONata built-in function millis() as argument; for the configured base time, pass the variable $baseTime . |
day |
String | no | Type of day; one of "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday", "day", "workday" or "weekend". If omitted, "day" (i.e., any day) is assumed. |
Return Value
true
for a match, false
otherwise.
$isSpecificDay()
Signature: $isSpecificDay(ts, day, month)
Checks if the given timestamp matches a specific day of a specific month or of any month.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp; must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date (today), pass the result of the JSONata built-in function millis() as argument; for the configured base time, pass the variable $baseTime . |
day |
Number | yes | The day of the month (1..31). |
month |
Number | no | The number of the month (1..12). If omitted, matches any month. |
Return Value
true
for a match, false
otherwise.
$matchesWeekdays()
Signature: $matchesWeekdays(ts, days)
Checks if the given timestamp matches one of the given weekdays.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp; must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date (today), pass the result of the JSONata built-in function millis() as argument; for the configured base time, pass the variable $baseTime . |
days |
Object | yes | May contain boolean properties with names of days of the week. If true , the timestamp must match that weekday, if false or not present, the timestamp must not match that weekday. |
Return Value
true
for a match, false
otherwise.
$matchesMonths()
Signature: $matchesMonths(ts, months)
Checks if the given timestamp matches one of the given months.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp; must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date (today), pass the result of the JSONata built-in function millis() as argument; for the configured base time, pass the variable $baseTime . |
months |
Object | yes | May contain boolean properties with names of months of the year. If true , the timestamp must match that month, if false or not present, the timestamp must not match that month. |
Return Value
true
for a match, false
otherwise.
$evaluateCondition()
Signature: $evaluateCondition(ts, condition)
Evaluates the given condition against the provided timestamp.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp; must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date and time (now), pass the result of the JSONata built-in function millis() as argument; for the configured base time, pass the variable $baseTime . |
condition |
Object | yes | Condition to evaluate, must be in the same format as conditions that can be loaded from context variables. |
Return Value
true
for a match according to the condition, false
otherwise.
Time Change Node Functions
The following functions are specific to the Time Change node.
$set()
Signature: $set(ts, part, value)
Sets the given part to the provided value and returns the modified timestamp.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp; must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date and time (now), pass the result of the JSONata built-in function millis() as argument. |
part |
String | yes | Name of the part to set; one of "year", "quarter", "month", "week", "weekday", "day", "hour", "minute", "second" or "millisecond". |
value |
Number | yes | Value to set the part of the timestamp to. |
Return Value
The return value is a timstamp as number of milliseconds since the Unix epoch.
$add()
Signature: $add(ts, value, unit)
Adds time to the given timestamp and returns the modified timestamp.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp; must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date and time (now), pass the result of the JSONata built-in function millis() as argument. |
value |
Number | yes | Amount of time to add. |
unit |
String | yes | Unit of time; one of "years", "quarters", "months", "weeks", "days", "hours", "minutes", "seconds" or "milliseconds". |
Return Value
The return value is a timstamp as number of milliseconds since the Unix epoch.
$subtract()
Signature: $subtract(ts, value, unit)
Subtracts time from the given timestamp and returns the modified timestamp.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp; must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date and time (now), pass the result of the JSONata built-in function millis() as argument. |
value |
Number | yes | Amount of time to subtract. |
unit |
String | yes | Unit of time; one of "years", "quarters", "months", "weeks", "days", "hours", "minutes", "seconds" or "milliseconds". |
Return Value
The return value is a timstamp as number of milliseconds since the Unix epoch.
$startOf()
Signature: $startOf(ts, part)
Sets the given part to its start value and returns the modified timestamp.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp; must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date and time (now), pass the result of the JSONata built-in function millis() as argument. |
part |
String | yes | Part to set to the start value; one of "year", "quarter", "month", "week", "day", "hour", "minute", "second" or "millisecond". |
Return Value
The return value is a timstamp as number of milliseconds since the Unix epoch.
$endOf()
Signature: $endOf(ts, part)
Sets the given part to its end value and returns the modified timestamp.
Arguments
Argument | Type | Mandatory | Description |
---|---|---|---|
ts |
Number, String | yes | Timestamp; must be either a number of milliseconds since the Unix epoch or a string that is parsable by moment.js. For the current date and time (now), pass the result of the JSONata built-in function millis() as argument. |
part |
String | yes | Part to set to the end value; one of "year", "quarter", "month", "week", "day", "hour", "minute", "second" or "millisecond". |
Return Value
The return value is a timstamp as number of milliseconds since the Unix epoch.