From 4e4fb4125b6f3c788c171fa2b59b0a111dd54af1 Mon Sep 17 00:00:00 2001 From: ljf Date: Tue, 5 Jun 2018 17:57:06 +0200 Subject: [PATCH 1/3] [fix] Display the date in a correct format --- moulinette/utils/serialize.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/moulinette/utils/serialize.py b/moulinette/utils/serialize.py index bc0e6d1d..692be658 100644 --- a/moulinette/utils/serialize.py +++ b/moulinette/utils/serialize.py @@ -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) + # Convert compatible containers into list + if isinstance(o, datetime.datetime) or isinstance(o, datetime.date): + return str(o) + # 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) From cf07c34fe3a3d7b8767e50e77e609253dd177cff Mon Sep 17 00:00:00 2001 From: "ljf (zamentur)" Date: Sat, 9 Jun 2018 11:38:43 +0200 Subject: [PATCH 2/3] [enh] Use isoformat date RFC 3339 --- moulinette/utils/serialize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moulinette/utils/serialize.py b/moulinette/utils/serialize.py index 692be658..cccf956d 100644 --- a/moulinette/utils/serialize.py +++ b/moulinette/utils/serialize.py @@ -27,7 +27,7 @@ class JSONExtendedEncoder(JSONEncoder): # Convert compatible containers into list if isinstance(o, datetime.datetime) or isinstance(o, datetime.date): - return str(o) + return o.isoformat() # Return the repr for object that json can't encode logger.warning('cannot properly encode in JSON the object %s, ' From c83d582313b8936000412b5bb48f418e580146e5 Mon Sep 17 00:00:00 2001 From: "ljf (zamentur)" Date: Sat, 9 Jun 2018 11:41:26 +0200 Subject: [PATCH 3/3] [fix] Bad comment --- moulinette/utils/serialize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moulinette/utils/serialize.py b/moulinette/utils/serialize.py index cccf956d..800cf1b0 100644 --- a/moulinette/utils/serialize.py +++ b/moulinette/utils/serialize.py @@ -25,7 +25,7 @@ class JSONExtendedEncoder(JSONEncoder): hasattr(o, '__iter__') and hasattr(o, 'next')): return list(o) - # Convert compatible containers into list + # 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()