Skip to content

Commit

Permalink
#225: Add timezone info to datetimes on DB backend
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed Apr 30, 2021
1 parent 0c68549 commit f30caa6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion datagateway_api/common/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from decimal import Decimal
import enum

from dateutil.tz import tzlocal
from sqlalchemy import (
BigInteger,
Boolean,
Expand All @@ -20,6 +21,7 @@
from sqlalchemy.orm import relationship
from sqlalchemy.orm.collections import InstrumentedList

from datagateway_api.common.date_handler import DateHandler
from datagateway_api.common.exceptions import DatabaseError, FilterError

Base = declarative_base()
Expand Down Expand Up @@ -78,7 +80,9 @@ def _make_serializable(self, field):
:return: The converted field
"""
if isinstance(field, datetime):
return str(field)
# Add timezone info to match ICAT backend
field = field.replace(tzinfo=tzlocal())
return DateHandler.datetime_object_to_str(field)
elif isinstance(field, Decimal):
return float(field)
else:
Expand Down

0 comments on commit f30caa6

Please sign in to comment.