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:
Data:
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:
Data:
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:
Data:
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:
Data:
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:
Data:
Result:
Example: Compare Date with Current Time
Rule:
Data:
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") |