Ensure server always return proper ISO encoded dates with timezone

This commit is contained in:
Lucas Verney 2018-08-02 11:14:38 +02:00
parent bb926abbc4
commit 343143e8e7

View File

@ -3,6 +3,7 @@
""" """
Helpers to implement a JSON API with Bottle. Helpers to implement a JSON API with Bottle.
""" """
import arrow
import datetime import datetime
import json import json
import re import re
@ -18,7 +19,7 @@ class DateAwareJSONEncoder(json.JSONEncoder):
""" """
def default(self, o): # pylint: disable=locally-disabled,E0202 def default(self, o): # pylint: disable=locally-disabled,E0202
if isinstance(o, (datetime.date, datetime.datetime)): if isinstance(o, (datetime.date, datetime.datetime)):
return o.isoformat() return arrow.get(o).isoformat()
return json.JSONEncoder.default(self, o) return json.JSONEncoder.default(self, o)