Interpolation macros
Besides referencing variables, the following macros can be called as part of jinja expressions, for example like this: {{ now_utc() }}.
now_utc
Returns the current date and time in the UTC timezone.
Examples:
'{{ now_utc() }}' -> '2021-09-01 00:00:00+00:00'
'{{ now_utc().strftime('%Y-%m-%d') }}' -> '2021-09-01'
today_utc
Returns the current date in UTC timezone. The output is a date object.
Examples:
'{{ today_utc() }}' -> '2021-09-01'
'{{ today_utc().strftime('%Y/%m/%d')}}' -> '2021/09/01'
timestamp
Converts a number or a string representing a datetime (formatted as ISO8601) to a timestamp. If the input is a number, it is converted to an int. If no timezone is specified, the string is interpreted as UTC.
Examples:
'{{ timestamp(1646006400) }}' -> 1646006400
'{{ timestamp('2022-02-28') }}' -> 1646006400
'{{ timestamp('2022-02-28T00:00:00Z') }}' -> 1646006400
'{{ timestamp('2022-02-28 00:00:00Z') }}' -> 1646006400
'{{ timestamp('2022-02-28T00:00:00-08:00') }}' -> 1646035200
Arguments:
datetime: A string formatted as ISO8601 or an integer representing a unix timestamp
max
Returns the largest object of a iterable, or or two or more arguments.
Examples:
'{{ max(2, 3) }}' -> 3
'{{ max([2, 3]) }}' -> 3
Arguments:
args: iterable or a sequence of two or more arguments
day_delta
Returns the datetime of now() + num_days.
Examples:
'{{ day_delta(1) }}' -> '2021-09-02T00:00:00.000000+0000'
'{{ day_delta(-1) }}' -> '2021-08-31:00:00.000000+0000'
'{{ day_delta(25, format='%Y-%m-%d') }}' -> '2021-09-02'
Arguments:
num_days: The number of days to add to nowformat: How to format the output string
duration
Converts an ISO8601 duration to datetime timedelta.
Examples:
'{{ duration('P1D') }}' -> '1 day, 0:00:00'
'{{ duration('P6DT23H') }}' -> '6 days, 23:00:00'
'{{ (now_utc() - duration('P1D')).strftime('%Y-%m-%dT%H:%M:%SZ') }}' -> '2021-08-31T00:00:00Z'
Arguments:
duration_string: A string representing an ISO8601 duration. See https://www.digi.com/resources/documentation/digidocs//90001488-13/reference/r_iso_8601_duration_format.htm for more details.
format_datetime
Converts a datetime or a datetime-string to the specified format.
Examples:
{{ format_datetime(config['start_time'], '%Y-%m-%d') }}
{{ format_datetime(config['start_date'], '%Y-%m-%dT%H:%M:%S.%fZ') }}
{{ format_datetime(config['start_date'], '%Y-%m-%dT%H:%M:%S.%fZ', '%a, %d %b %Y %H:%M:%S %z') }}
Arguments:
datetime: The datetime object or a string to convert. If datetime is a string, it must be formatted as ISO8601.format: The datetime format.input_format: (optional) The datetime format in the case it is an string.
str_to_datetime
Converts a string to a datetime object with UTC timezone.
Examples:
{{ str_to_datetime('2022-01-14') }}
{{ str_to_datetime('2022-01-01 13:45:30') }}
{{ str_to_datetime('2022-01-01T13:45:30+00:00') }}
{{ str_to_datetime('2022-01-01T13:45:30.123456Z') }}
Arguments:
s: The string to convert.