I have input strings with dates in, I guess, iso8601_micro format with UTC offset.
2021-12-01 16:05:38.051000+03:00
I want to convert them to date time. (So I could compare it with interval provided by user) But Ansible stumbles after dot on microtime.
- debug:
msg:
- "{{ ('2021-12-01 16:05:38.051000+03:00')| to_datetime }}"
and yields "unconverted data remains" error:
{
"msg": "the field 'args' has an invalid value ({u'msg': [u\"{{ ('2021-12-01 16:05:38.051000+03:00')| to_datetime }}\"]}), and could not be converted to an dict.The error was: unconverted data remains: .051000+03:00\n\n
}
I've tried to pass it's format to datetime filter
- debug:
msg:
- "{{ ('2021-12-01 16:05:38.051000+03:00')| to_datetime('%Y-%m-%d %H:%M:%S.%f%z') }}"
But I'm getting exactly the same output.
I've tried the inverse way.
- debug:
msg:
- "{{ '%Y-%m-%d %H:%M:%S.%f%z'|strftime }}"
This time %f format directive was just ignored:
{
"msg": [
"2021-12-16 00:29:18.%f+0000"
]
}
But %f directive should be valid I at least, according to https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html and https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior
So is this the bug?
Or it's just me?