community.general.to_time_unit (3.8.10) — filter

Converte a duration string to the given time unit

| "added in version" 0.2.0 of community.general"

Authors: René Moser (@resmo)

Install collection

Install with ansible-galaxy collection install community.general:==3.8.10


Add to requirements.yml

  collections:
    - name: community.general
      version: 3.8.10

Description

Parse a human readable time duration string and convert to the given time unit.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Convert a duration into seconds
  ansible.builtin.debug:
    msg: "{{ '1053d 17h 53m -10s 391ms' | community.general.to_time_unit('s') }}"

Inputs

    
unit:
    choices:
    - millisecond
    - milliseconds
    - ms
    - msec
    - msecs
    - msecond
    - mseconds
    - s
    - sec
    - secs
    - second
    - seconds
    - h
    - hour
    - hours
    - hs
    - m
    - min
    - mins
    - minute
    - minutes
    - d
    - ds
    - day
    - days
    - w
    - ws
    - week
    - weeks
    - mo
    - mos
    - month
    - months
    - y
    - ys
    - year
    - years
    default: ms
    description:
    - Time unit to convert the duration to.
    type: string

year:
    default: 365
    description:
    - Number of days per year.
    type: float

month:
    default: 30
    description:
    - Number of days per month.
    type: float

_input:
    description:
    - The time string to convert.
    - Can use the units C(y) and C(year) for a year, C(mo) and C(month) for a month, C(w)
      and C(week) for a week, C(d) and C(day) for a day, C(h) and C(hour) for a hour,
      C(m), C(min) and C(minute) for minutes, C(s), C(sec) and C(second) for seconds,
      C(ms), C(msec), C(msecond) and C(millisecond) for milliseconds. The suffix C(s)
      can be added to a unit as well, so C(seconds) is the same as C(second).
    - Valid strings are space separated combinations of an integer with an optional minus
      sign and a unit.
    - Examples are C(1h), C(-5m), and C(3h -5m 6s).
    required: true
    type: string

Outputs

_value:
  description: Number of time units.
  type: float