implement text.parse_datetime()

This commit is contained in:
Mike Fährmann
2019-05-08 00:00:00 +02:00
parent 049e9fd6ce
commit d09864b581
2 changed files with 29 additions and 0 deletions

View File

@@ -223,6 +223,20 @@ def parse_timestamp(ts, default=None):
return default
def parse_datetime(date_string, format="%Y-%m-%dT%H:%M:%S%z"):
"""Create a datetime object by parsing 'date_string'"""
try:
d = datetime.datetime.strptime(date_string, format)
o = d.utcoffset()
if o is not None:
d = d.replace(tzinfo=None) - o # convert to naive UTC
return d
except TypeError:
return None
except (ValueError, OverflowError):
return date_string
if os.name == "nt":
clean_path = clean_path_windows
else: