parent
9da880182b
commit
6289570234
3 changed files with 5 additions and 1 deletions
3
changelogs/fragments/71257-strftime-float.yml
Normal file
3
changelogs/fragments/71257-strftime-float.yml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
bugfixes:
|
||||||
|
- strftime filter - Input epoch is allowed to be a float
|
||||||
|
(https://github.com/ansible/ansible/issues/71257)
|
|
@ -102,7 +102,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 '''
|
''' return a date string using string. See https://docs.python.org/2/library/time.html#time.strftime for format '''
|
||||||
if second is not None:
|
if second is not None:
|
||||||
try:
|
try:
|
||||||
second = int(second)
|
second = float(second)
|
||||||
except Exception:
|
except Exception:
|
||||||
raise AnsibleFilterError('Invalid value for epoch value (%s)' % second)
|
raise AnsibleFilterError('Invalid value for epoch value (%s)' % second)
|
||||||
return time.strftime(string_format, time.localtime(second))
|
return time.strftime(string_format, time.localtime(second))
|
||||||
|
|
|
@ -325,6 +325,7 @@
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- '"%Y-%m-%d"|strftime(1585247522) == "2020-03-26"'
|
- '"%Y-%m-%d"|strftime(1585247522) == "2020-03-26"'
|
||||||
|
- '"%Y-%m-%d"|strftime("1585247522.0") == "2020-03-26"'
|
||||||
- '("%Y"|strftime(None)).startswith("20")' # Current date, can't check much there.
|
- '("%Y"|strftime(None)).startswith("20")' # Current date, can't check much there.
|
||||||
- strftime_fail is failed
|
- strftime_fail is failed
|
||||||
- '"Invalid value for epoch value" in strftime_fail.msg'
|
- '"Invalid value for epoch value" in strftime_fail.msg'
|
||||||
|
|
Loading…
Reference in a new issue