use logilab.common.date.ustrftime in json encoder to work around datetime.strftime limitation on dates < 1900 stable
authorAlexandre Fayolle <alexandre.fayolle@logilab.fr>
Mon, 23 Aug 2010 09:07:20 +0200
branchstable
changeset 6134 272cfcc10a28
parent 6133 6f3eabbbdf2e
child 6135 e4b37742f75a
use logilab.common.date.ustrftime in json encoder to work around datetime.strftime limitation on dates < 1900
utils.py
--- a/utils.py	Mon Aug 23 08:46:24 2010 +0200
+++ b/utils.py	Mon Aug 23 09:07:20 2010 +0200
@@ -334,7 +334,7 @@
     json_dumps = None
 
 else:
-
+    from logilab.common.date import ustrftime
     class CubicWebJsonEncoder(json.JSONEncoder):
         """define a json encoder to be able to encode yams std types"""
 
@@ -344,9 +344,9 @@
                 d['eid'] = obj.eid
                 return d
             if isinstance(obj, datetime.datetime):
-                return obj.strftime('%Y/%m/%d %H:%M:%S')
+                return ustrftime(obj, '%Y/%m/%d %H:%M:%S')
             elif isinstance(obj, datetime.date):
-                return obj.strftime('%Y/%m/%d')
+                return ustrftime(obj, '%Y/%m/%d')
             elif isinstance(obj, datetime.time):
                 return obj.strftime('%H:%M:%S')
             elif isinstance(obj, datetime.timedelta):