Prevent python datetime from converting to Javascript datetime before json encoding.

Previously the conversion from python to Javascript datetime objects was
adding timezone information, which was causing the date to render
incorrectly because the users timezone was different than the encoded
time zone.
This commit is contained in:
leigh-mil 2019-02-01 11:12:54 -05:00
parent b4cd657d62
commit 4c775517b9

View File

@ -1,4 +1,5 @@
from flask.json import JSONEncoder from flask.json import JSONEncoder
from datetime import date
from atst.models.attachment import Attachment from atst.models.attachment import Attachment
@ -6,4 +7,6 @@ class CustomJSONEncoder(JSONEncoder):
def default(self, obj): def default(self, obj):
if isinstance(obj, Attachment): if isinstance(obj, Attachment):
return obj.filename return obj.filename
if isinstance(obj, date):
return obj.strftime("%Y-%m-%d")
return JSONEncoder.default(self, obj) return JSONEncoder.default(self, obj)