Machine readable duration

Following up on https://github.com/ansible/ansible/pull/75370

I would like a machine readable duration for how long a command runs. I was told I could use existing filters. How would I accomplish that? strftime does not support parsing the output of str(timedelta), which is currently used for duration (see https://bugs.python.org/issue41254)

I was not aware of the datetime bug (was thinking to_datetime &
strftime), but it is still simple to do in jinja:

   - debug: msg='{{seconds}}'
     vars:
       d: "{{res['delta'].split(':')}}"
       seconds : "{{ d[0]|int * 3600 + d[1]|int * 60 + d[2]|float }}"

That doesn’t work for longer periods of time: “2 days, 2:02:02.000002”

It’s definitely possible to parse (right now I’m using regex in Python), it’s just annoying to have to manually write a regex for a non-standard format unique to Python timedeltas

Makes sense. If it weren’t for backwards compatibility I would definitely vote duration is machine readable, but maybe that’s an issue with str(timedelta). Guess I’ll just use regex :person_shrugging: