mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 21:32:49 +00:00
Added to_datetime filter (#17145)
* Added to_datetime filter * Added to_datetime filter documentation
This commit is contained in:
committed by
Michael Scherer
parent
2ffb136b3f
commit
d80d986a38
@@ -34,6 +34,7 @@ import hashlib
|
||||
import string
|
||||
from functools import partial
|
||||
from random import SystemRandom, shuffle
|
||||
from datetime import datetime
|
||||
import uuid
|
||||
|
||||
import yaml
|
||||
@@ -116,6 +117,10 @@ def to_bool(a):
|
||||
else:
|
||||
return False
|
||||
|
||||
def to_datetime(string, format="%Y-%d-%m %H:%M:%S"):
|
||||
return datetime.strptime(string, format)
|
||||
|
||||
|
||||
def quote(a):
|
||||
''' return its argument quoted for shell usage '''
|
||||
return pipes.quote(a)
|
||||
@@ -393,6 +398,9 @@ class FilterModule(object):
|
||||
'to_nice_yaml': to_nice_yaml,
|
||||
'from_yaml': yaml.safe_load,
|
||||
|
||||
#date
|
||||
'to_datetime': to_datetime,
|
||||
|
||||
# path
|
||||
'basename': partial(unicode_wrap, os.path.basename),
|
||||
'dirname': partial(unicode_wrap, os.path.dirname),
|
||||
|
||||
Reference in New Issue
Block a user