Can PyYAML parse iso8601 dates?
If you don't like the default behaviour (naive utc datetime, utc offset lost) you could provide your own constructor:
import dateutil.parser
import yaml
def timestamp_constructor(loader, node):
return dateutil.parser.parse(node.value)
yaml.add_constructor(u'tag:yaml.org,2002:timestamp', timestamp_constructor)
print(repr(yaml.load("2001-12-14T21:59:43.10-05:00")))
# -> datetime.datetime(2001, 12, 14, 21, 59, 43, 100000, tzinfo=tzoffset(None, -18000))
This is fixed as of pyyaml 5.3 (Github Pull Request)
>>> yaml.safe_load('2020-12-17t14:40:00+02:00')
datetime.datetime(2020, 12, 17, 14, 40, tzinfo=datetime.timezone(datetime.timedelta(seconds=7200)))