summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Martz <matt@sivel.net>2020-08-27 11:09:05 -0500
committerGitHub <noreply@github.com>2020-08-27 11:09:05 -0500
commit48d99c0ff1c4b48d84e21b9c53303ef2bac055d1 (patch)
treedddbd8620bcf53b9c2dbee8e4250fb207b80d09a
parent4a5aac0ac1c0fd32592a97137707f626288b148e (diff)
downloadansible-48d99c0ff1c4b48d84e21b9c53303ef2bac055d1.tar.gz
[stable-2.9] epoch can be a float with strftime filter. Fixes #71257 (#71314). (#71320)
(cherry picked from commit 6289570234ff924a057e8d89ec00606e0ecca0f6) Co-authored-by: Matt Martz <matt@sivel.net>
-rw-r--r--changelogs/fragments/71257-strftime-float.yml3
-rw-r--r--lib/ansible/plugins/filter/core.py2
2 files changed, 4 insertions, 1 deletions
diff --git a/changelogs/fragments/71257-strftime-float.yml b/changelogs/fragments/71257-strftime-float.yml
new file mode 100644
index 0000000000..d5e3bf46fa
--- /dev/null
+++ b/changelogs/fragments/71257-strftime-float.yml
@@ -0,0 +1,3 @@
+bugfixes:
+- strftime filter - Input epoch is allowed to be a float
+ (https://github.com/ansible/ansible/issues/71257)
diff --git a/lib/ansible/plugins/filter/core.py b/lib/ansible/plugins/filter/core.py
index cb45f6e8c8..1fc6790a4d 100644
--- a/lib/ansible/plugins/filter/core.py
+++ b/lib/ansible/plugins/filter/core.py
@@ -107,7 +107,7 @@ def strftime(string_format, second=None):
''' return a date string using string. See https://docs.python.org/2/library/time.html#time.strftime for format '''
if second is not None:
try:
- second = int(second)
+ second = float(second)
except Exception:
raise AnsibleFilterError('Invalid value for epoch value (%s)' % second)
return time.strftime(string_format, time.localtime(second))