1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

time_filter: allow 0 to return 0 (#4612)

* time_filter: allow 0 to return 0

* add changelog

* Update changelogs/fragments/4612-time_filter_zero.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
René Moser 2022-05-04 07:38:16 +02:00 committed by GitHub
parent 8d37591605
commit dd9afc09a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 0 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- to_time_unit filter plugins - the time filters has been extended to also allow ``0`` as input (https://github.com/ansible-collections/community.general/pull/4612).

View file

@ -46,6 +46,11 @@ def multiply(factors):
def to_time_unit(human_time, unit='ms', **kwargs): def to_time_unit(human_time, unit='ms', **kwargs):
''' Return a time unit from a human readable string ''' ''' Return a time unit from a human readable string '''
# No need to handle 0
if human_time == "0":
return 0
unit_to_short_form = UNIT_TO_SHORT_FORM unit_to_short_form = UNIT_TO_SHORT_FORM
unit_factors = UNIT_FACTORS unit_factors = UNIT_FACTORS

View file

@ -4,6 +4,13 @@
# and should not be used as examples of how to write Ansible roles # # and should not be used as examples of how to write Ansible roles #
#################################################################### ####################################################################
- name: test zero is 0
assert:
that:
- "('0' | community.general.to_milliseconds) == 0"
- "('0' | community.general.to_seconds) == 0"
- "('0' | community.general.to_minutes) == 0"
- name: test to_milliseconds filter - name: test to_milliseconds filter
assert: assert:
that: that: