diff --git a/postgrestutils/client/utils.py b/postgrestutils/client/utils.py index dbe2883212dc442cd33f0e5ce54a0cd1a35baf64..6eae8d43bc13e9a043243ea3041cd50ca1fda58a 100644 --- a/postgrestutils/client/utils.py +++ b/postgrestutils/client/utils.py @@ -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