Date & Time Operators
Date and time operators allow you to work with date-related operations in DataLogic-rs.
datetime
The datetime
operator converts a string to a datetime object.
Syntax
{ "datetime": [dateString] }
Parameters
Parameter | Description |
---|---|
dateString | A string in ISO 8601 format (e.g., "2022-07-06T13:20:06Z") |
Example: Create a datetime from ISO string
Rule:
xxxxxxxxxx
{
"datetime": [
"2022-07-06T13:20:06Z"
]
}
Data:
xxxxxxxxxx
{}
Result:
timestamp
The timestamp
operator parses a duration string into a duration object.
Syntax
{ "timestamp": [durationString] }
Parameters
Parameter | Description |
---|---|
durationString | A string in format "nd:nh:nm:ns" (days, hours, minutes, seconds) |
Example: Parse duration string
Rule:
xxxxxxxxxx
{
"timestamp": [
"1d:2h:3m:4s"
]
}
Data:
xxxxxxxxxx
{}
Result:
parse_date
The parse_date
operator parses a date string using a specified format.
Syntax
{ "parse_date": [dateString, formatString] }
Parameters
Parameter | Description |
---|---|
dateString | The date string to parse |
formatString | Format pattern (e.g., "yyyy-MM-dd") |
Example: Parse date with format
Rule:
xxxxxxxxxx
{
"parse_date": [
"2022-07-06",
"yyyy-MM-dd"
]
}
Data:
xxxxxxxxxx
{}
Result:
format_date
The format_date
operator formats a datetime according to a specified format string.
Syntax
{ "format_date": [dateValue, formatString] }
Parameters
Parameter | Description |
---|---|
dateValue | Datetime value to format |
formatString | Format pattern (e.g., "yyyy-MM-dd HH:mm:ss") |
Example: Format a date
Rule:
xxxxxxxxxx
{
"format_date": [
{
"datetime": [
"2022-07-06T13:20:06Z"
]
},
"yyyy/MM/dd HH:mm"
]
}
Data:
xxxxxxxxxx
{}
Result:
now
The now
operator returns the current timestamp as a Unix timestamp (seconds since January 1, 1970).
Syntax
{ "now": [] }
Parameters
Parameter | Description |
---|---|
None | No parameters required |
Example: Get Current Timestamp
Rule:
xxxxxxxxxx
{
"now": []
}
Data:
xxxxxxxxxx
{}
Result:
Example: Compare Date with Current Time
Rule:
xxxxxxxxxx
{
">": [
{
"now": []
},
{
"val": "expirationDate"
}
]
}
Data:
xxxxxxxxxx
{
"expirationDate": 1609459200
}
Result:
date_diff
The date_diff
operator calculates the difference between two timestamps in the specified unit.
Syntax
{ "date_diff": [timestamp1, timestamp2, unit] }
Parameters
Parameter | Description |
---|---|
timestamp1 | First timestamp (Unix timestamp) |
timestamp2 | Second timestamp (Unix timestamp) |
unit | Unit of time ("seconds", "minutes", "hours", "days", "weeks") |
Example: Calculate Time Difference in Days
Rule:
xxxxxxxxxx
{
"date_diff": [
{
"val": "currentDate"
},
{
"val": "pastDate"
},
"days"
]
}
Data:
xxxxxxxxxx
{
"currentDate": "2022-07-15T13:20:06Z",
"pastDate": "2022-07-06T13:20:06Z"
}
Result:
Example: Check if an Event is Within the Next Hour
Rule:
xxxxxxxxxx
"val": "eventTime"
{
"and": [
{
">": [
{
"val": "eventTime"
},
{
"now": []
}
]
},
{
"<": [
{
Data:
xxxxxxxxxx
{
"eventTime": 1621352576
}
Result: