mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
[enh] Transform naive date into UTC aware date
This commit is contained in:
parent
5125d948af
commit
57602c5a1c
3 changed files with 8 additions and 2 deletions
3
debian/control
vendored
3
debian/control
vendored
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue