Date Time
Various operators for parsing and manipulating dates.
Date time formattings
This uses Golang's built in time library for parsing and formatting date times.
When not specified, the RFC3339 standard is assumed 2006-01-02T15:04:05Z07:00
for parsing.
To specify a custom parsing format, use the with_dtf
operator. The first parameter sets the datetime parsing format for the expression in the second parameter. The expression can be any valid yq
expression tree.
See the library docs for examples of formatting options.
Timezones
This uses Golang's built in LoadLocation function to parse timezones strings. See the library docs for more details.
Durations
Durations are parsed using Golang's built in ParseDuration function.
You can add durations to time using the +
operator.
Format: from standard RFC3339 format
Providing a single parameter assumes a standard RFC3339 datetime format. If the target format is not a valid yaml datetime format, the result will be a string tagged node.
Given a sample.yml file of:
then
will output
Format: from custom date time
Use with_dtf to set a custom datetime format for parsing.
Given a sample.yml file of:
then
will output
Format: get the day of the week
Given a sample.yml file of:
then
will output
Now
Given a sample.yml file of:
then
will output
From Unix
Converts from unix time. Note, you don't have to pipe through the tz operator :)
Running
will output
To Unix
Converts to unix time
Running
will output
Timezone: from standard RFC3339 format
Returns a new datetime in the specified timezone. Specify standard IANA Time Zone format or 'utc', 'local'. When given a single parameter, this assumes the datetime is in RFC3339 format.
Given a sample.yml file of:
then
will output
Timezone: with custom format
Specify standard IANA Time Zone format or 'utc', 'local'
Given a sample.yml file of:
then
will output
Add and tz custom format
Specify standard IANA Time Zone format or 'utc', 'local'
Given a sample.yml file of:
then
will output
Date addition
Given a sample.yml file of:
then
will output
Date subtraction
You can subtract durations from dates. Assumes RFC3339 date time format, see date-time operators for more information.
Given a sample.yml file of:
then
will output
Date addition - custom format
Given a sample.yml file of:
then
will output
Date script with custom format
You can embed full expressions in with_dtf if needed.
Given a sample.yml file of:
then
will output
Last updated