##// END OF EJS Templates
use `isoformat()` in jsonutil...
MinRK -
Show More
@@ -33,7 +33,7 b" next_attr_name = '__next__' if py3compat.PY3 else 'next'"
33 33
34 34 # timestamp formats
35 35 ISO8601="%Y-%m-%dT%H:%M:%S.%f"
36 ISO8601_PAT=re.compile(r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+$")
36 ISO8601_PAT=re.compile(r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+(Z?[\+\-]\d{2}:?\d{2})?$")
37 37
38 38 #-----------------------------------------------------------------------------
39 39 # Classes and functions
@@ -72,7 +72,9 b' def extract_dates(obj):'
72 72 obj = [ extract_dates(o) for o in obj ]
73 73 elif isinstance(obj, basestring):
74 74 if ISO8601_PAT.match(obj):
75 obj = datetime.strptime(obj, ISO8601)
75 # FIXME: add actual timezone support
76 notz = obj.split('Z',1)[0]
77 obj = datetime.strptime(notz, ISO8601)
76 78 return obj
77 79
78 80 def squash_dates(obj):
@@ -84,13 +86,13 b' def squash_dates(obj):'
84 86 elif isinstance(obj, (list, tuple)):
85 87 obj = [ squash_dates(o) for o in obj ]
86 88 elif isinstance(obj, datetime):
87 obj = obj.strftime(ISO8601)
89 obj = obj.isoformat()
88 90 return obj
89 91
90 92 def date_default(obj):
91 93 """default function for packing datetime objects in JSON."""
92 94 if isinstance(obj, datetime):
93 return obj.strftime(ISO8601)
95 return obj.isoformat()
94 96 else:
95 97 raise TypeError("%r is not JSON serializable"%obj)
96 98
General Comments 0
You need to be logged in to leave comments. Login now