mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Merge pull request #163 from YunoHost/fix-datetime-format
[fix] Display the date in a correct format
This commit is contained in:
commit
fe22b1024c
1 changed files with 5 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
import logging
|
||||
from json.encoder import JSONEncoder
|
||||
import datetime
|
||||
|
||||
logger = logging.getLogger('moulinette.utils.serialize')
|
||||
|
||||
|
@ -24,6 +25,10 @@ class JSONExtendedEncoder(JSONEncoder):
|
|||
hasattr(o, '__iter__') and hasattr(o, 'next')):
|
||||
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):
|
||||
return o.isoformat()
|
||||
|
||||
# Return the repr for object that json can't encode
|
||||
logger.warning('cannot properly encode in JSON the object %s, '
|
||||
'returned repr is: %r', type(o), o)
|
||||
|
|
Loading…
Reference in a new issue