Do not fail while parsing illegal dates. Return None instead.

This commit is contained in:
Simone Pierazzini 2019-07-26 12:11:00 +02:00
parent bd033a9f7e
commit 25c619032f

View file

@ -176,7 +176,11 @@ def toDatetime(value, format=None):
"""
if value and value is not None:
if format:
value = datetime.strptime(value, format)
try:
value = datetime.strptime(value, format)
except ValueError:
# parsing failed
return None
else:
# https://bugs.python.org/issue30684
# And platform support for before epoch seems to be flaky.