Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ea0e1bc

Browse files
committed
tweak regexp handling of tzinfo
allows for excluding the 'Z' from the timezone info
1 parent b70960f commit ea0e1bc

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

IPython/utils/jsonutil.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
# timestamp formats
3535
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+Z?([\+\-]\d{2}:?\d{2})?$")
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})?$")
3737

3838
#-----------------------------------------------------------------------------
3939
# Classes and functions
@@ -71,9 +71,11 @@ def extract_dates(obj):
7171
elif isinstance(obj, (list, tuple)):
7272
obj = [ extract_dates(o) for o in obj ]
7373
elif isinstance(obj, basestring):
74-
if ISO8601_PAT.match(obj):
74+
m = ISO8601_PAT.match(obj)
75+
if m:
7576
# FIXME: add actual timezone support
76-
notz = obj.split('Z',1)[0]
77+
# this just drops the timezone info
78+
notz = m.groups()[0]
7779
obj = datetime.strptime(notz, ISO8601)
7880
return obj
7981

0 commit comments

Comments
 (0)