mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 13:20:23 -07:00
Time filter improvements (#359)
* Adjust target directory so that ansible-test knows what to run when filters change. * Divide by multiple instead of multiplying with product of 1/factor to improve numerical robustness. * Allow to say what a year or month is (in days). * Add changelog fragment announcing the time filters. * Make sure unknown keyword args result in errors. * Fix formatting screw-up.
This commit is contained in:
parent
801b1edcbe
commit
0399127d11
4 changed files with 49 additions and 27 deletions
|
@ -38,24 +38,29 @@
|
|||
- "('1week' | community.general.to_days) == 7"
|
||||
- "('2weeks' | community.general.to_days) == 14"
|
||||
- "('1mo' | community.general.to_days) == 30"
|
||||
- "('1mo' | community.general.to_days(month=28)) == 28"
|
||||
|
||||
- name: test to_weeks filter
|
||||
assert:
|
||||
that:
|
||||
- "('1y' | community.general.to_weeks | int) == 52"
|
||||
- "('7d' | community.general.to_weeks) == 1"
|
||||
- "('1mo' | community.general.to_weeks(month=28)) == 4"
|
||||
|
||||
- name: test to_months filter
|
||||
assert:
|
||||
that:
|
||||
- "('30d' | community.general.to_months) == 1"
|
||||
- "('1year' | community.general.to_months | int) == 12"
|
||||
- "('5years' | community.general.to_months(month=30, year=360)) == 60"
|
||||
- "('1years' | community.general.to_months(month=2, year=34)) == 17"
|
||||
|
||||
- name: test to_years filter
|
||||
assert:
|
||||
that:
|
||||
- "('365d' | community.general.to_years | int) == 1"
|
||||
- "('12mo' | community.general.to_years | round(0, 'ceil')) == 1"
|
||||
- "('24mo' | community.general.to_years(month=30, year=360)) == 2"
|
||||
|
||||
- name: test fail unknown unit
|
||||
debug:
|
||||
|
@ -80,3 +85,15 @@
|
|||
that:
|
||||
- res is failed
|
||||
- "'to_time_unit() can not interpret following string' in res.msg"
|
||||
|
||||
- name: test fail unknown kwarg
|
||||
debug:
|
||||
msg: "{{ '1s' | community.general.to_time_unit('s', second=23) }}"
|
||||
ignore_errors: yes
|
||||
register: res
|
||||
|
||||
- name: test fail unknown kwarg
|
||||
assert:
|
||||
that:
|
||||
- res is failed
|
||||
- "'to_time_unit() got unknown keyword arguments' in res.msg"
|
Loading…
Add table
Add a link
Reference in a new issue