diff --git a/changelogs/fragments/71257-strftime-float.yml b/changelogs/fragments/71257-strftime-float.yml new file mode 100644 index 00000000000..d5e3bf46faf --- /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 cb45f6e8c87..1fc6790a4d9 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))