Skip to content
Snippets Groups Projects
Commit d00ca304 authored by Fynn Becker's avatar Fynn Becker :crab:
Browse files

Fix datetime parsing for production (python 3.5)

parent bcef7d65
No related branches found
No related tags found
No related merge requests found
......@@ -35,7 +35,7 @@ def clean_parts(parts):
def datetime_parser(json_dict):
for key, value in json_dict.items():
if isinstance(value, str):
if DJANGO and False:
if DJANGO:
try:
parsed_dt = dateparse.parse_datetime(value)
if django_tz.is_naive(parsed_dt):
......@@ -50,8 +50,10 @@ def datetime_parser(json_dict):
if parts.get('offsetsign') and parts.get('offsethours') and parts.get('offsetminutes'):
sign = -1 if parts.pop('offsetsign', '+') == '-' else 1
tz = timezone(offset=sign * timedelta(hours=int(parts.pop('offsethours')), minutes=int(parts.pop('offsetminutes'))))
parsed_dt = datetime(**parts).replace(tzinfo=tz)
parsed_dt = datetime(**parts).replace(tzinfo=tz).astimezone()
else:
parsed_dt = datetime(**parts)
json_dict[key] = parsed_dt.astimezone()
# naive datetime so we assume local time
local_tz = datetime.now(timezone.utc).astimezone().tzinfo
parsed_dt = datetime(**parts).replace(tzinfo=local_tz)
json_dict[key] = parsed_dt
return json_dict
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment