[enh] Transform naive date into UTC aware date

This commit is contained in:
ljf 2018-12-10 00:00:49 +01:00
parent 5125d948af
commit 57602c5a1c
3 changed files with 8 additions and 2 deletions

3
debian/control vendored
View file

@ -16,7 +16,8 @@ Depends: ${misc:Depends}, ${python:Depends},
python-gnupg,
python-gevent-websocket,
python-argcomplete,
python-psutil
python-psutil,
python-tz
Replaces: yunohost-cli
Breaks: yunohost-cli
Description: prototype interfaces with ease in Python

View file

@ -103,6 +103,8 @@ def pretty_date(_date):
Argument:
- date -- The date or datetime to display
"""
if _date.tzinfo is None:
_date = _date.replace(tzinfo=pytz.utc)
if time.daylight:
offsetHour = time.altzone / 3600
else:

View file

@ -1,6 +1,7 @@
import logging
from json.encoder import JSONEncoder
import datetime
import pytz
logger = logging.getLogger('moulinette.utils.serialize')
@ -26,7 +27,9 @@ class JSONExtendedEncoder(JSONEncoder):
return list(o)
# Display the date in its iso format ISO-8601 Internet Profile (RFC 3339)
if isinstance(o, datetime.datetime) or isinstance(o, datetime.date):
if isinstance(o, datetime.date):
if o.tzinfo is None:
o = o.replace(tzinfo=pytz.utc)
return o.isoformat()
# Return the repr for object that json can't encode