summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Coca <bcoca@users.noreply.github.com>2022-11-23 12:27:09 -0500
committerGitHub <noreply@github.com>2022-11-23 12:27:09 -0500
commit505b29b2a981eabb2dd84bc66d37704bab91c3f9 (patch)
tree890e21e26bf3cfc24f8c73fb6a055a6132c93b28
parentb148fd8dd74c8599f809f71117a86577ccfb0638 (diff)
downloadansible-505b29b2a981eabb2dd84bc66d37704bab91c3f9.tar.gz
more strftime docs (#79417)
* more strftime docs fixes #79397 Co-authored-by: Matt Martz <matt@sivel.net> Co-authored-by: Don Naro <dnaro@redhat.com> Co-authored-by: Sloane Hertel <19572925+s-hertel@users.noreply.github.com>
-rw-r--r--changelogs/fragments/strftime_docs.yml2
-rw-r--r--lib/ansible/plugins/filter/strftime.yml12
2 files changed, 13 insertions, 1 deletions
diff --git a/changelogs/fragments/strftime_docs.yml b/changelogs/fragments/strftime_docs.yml
new file mode 100644
index 0000000000..1349806dfe
--- /dev/null
+++ b/changelogs/fragments/strftime_docs.yml
@@ -0,0 +1,2 @@
+minor_changes:
+ - strftime filter, additional docs and links to source of truth.
diff --git a/lib/ansible/plugins/filter/strftime.yml b/lib/ansible/plugins/filter/strftime.yml
index 6cb8874ad5..a1d8b9215d 100644
--- a/lib/ansible/plugins/filter/strftime.yml
+++ b/lib/ansible/plugins/filter/strftime.yml
@@ -5,7 +5,7 @@ DOCUMENTATION:
description:
- Using Python's C(strftime) function, take a data formating string and a date/time to create a formated date.
notes:
- - This is a passthrough to Python's C(stftime).
+ - This is a passthrough to Python's C(stftime), for a complete set of formatting options go to https://strftime.org/.
positional: _input, second, utc
options:
_input:
@@ -23,6 +23,8 @@ DOCUMENTATION:
default: false
EXAMPLES: |
+ # for a complete set of features go to https://strftime.org/
+
# Display year-month-day
{{ '%Y-%m-%d' | strftime }}
# => "2021-03-19"
@@ -39,6 +41,14 @@ EXAMPLES: |
{{ '%Y-%m-%d' | strftime(0) }} # => 1970-01-01
{{ '%Y-%m-%d' | strftime(1441357287) }} # => 2015-09-04
+ # complex examples
+ vars:
+ date1: '2022-11-15T03:23:13.686956868Z'
+ date2: '2021-12-15T16:06:24.400087Z'
+ date_short: '{{ date1|regex_replace("([^.]+)(\.\d{6})(\d*)(.+)", "\1\2\4") }}' #shorten microseconds
+ iso8601format: '%Y-%m-%dT%H:%M:%S.%fZ'
+ date_diff_isoed: '{{ (date1|to_datetime(isoformat) - date2|to_datetime(isoformat)).total_seconds() }}'
+
RETURN:
_value:
description: A formatted date/time string.