Date & Time Operators
Date and time operators allow you to work with date-related operations in DataLogic-rs. These operators preserve timezone information and support timezone offset extraction.
datetime
The datetime
operator converts a string to a datetime object, preserving timezone information when present.
Syntax
{ "datetime": [dateString] }
Parameters
Parameter | Description |
---|---|
dateString | A string in ISO 8601 format with optional timezone offset (e.g., "2022-07-06T13:20:06Z", "2022-07-06T13:20:06+05:00") |
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", "z" for timezone offset) |
Format Patterns
Pattern | Description | Example |
---|---|---|
yyyy | 4-digit year | 2022 |
MM | 2-digit month | 07 |
dd | 2-digit day | 06 |
HH | 24-hour format hour | 13 |
mm | Minutes | 20 |
ss | Seconds | 06 |
z | Timezone offset in ±HHMM format | +0500, -0800 |
Example: Format a date
Rule:
Data:
Result:
Example: Extract timezone offset
Rule:
Data:
Result:
Example: Preserve timezone in formatting
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") |