[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-gnupg,
python-gevent-websocket, python-gevent-websocket,
python-argcomplete, python-argcomplete,
python-psutil python-psutil,
python-tz
Replaces: yunohost-cli Replaces: yunohost-cli
Breaks: yunohost-cli Breaks: yunohost-cli
Description: prototype interfaces with ease in Python Description: prototype interfaces with ease in Python

View file

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

View file

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