From e631d2783d28c3a93ef24cac26ddfb389d299e77 2014-02-12 04:03:32 From: MinRK Date: 2014-02-12 04:03:32 Subject: [PATCH] allow datestamps to exclude microseconds datetime.isoformat() excludes microseconds when the value is zero, causing a 1/1000000 failure on most platforms, and 1/1000 on Windows due to millisecond datetime resolution. --- diff --git a/IPython/utils/jsonutil.py b/IPython/utils/jsonutil.py index 9fed8d2..68630be 100644 --- a/IPython/utils/jsonutil.py +++ b/IPython/utils/jsonutil.py @@ -34,7 +34,7 @@ next_attr_name = '__next__' if py3compat.PY3 else 'next' # timestamp formats ISO8601 = "%Y-%m-%dT%H:%M:%S.%f" -ISO8601_PAT=re.compile(r"^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{1,6})Z?([\+\-]\d{2}:?\d{2})?$") +ISO8601_PAT=re.compile(r"^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})(\.\d{1,6})?Z?([\+\-]\d{2}:?\d{2})?$") #----------------------------------------------------------------------------- # Classes and functions @@ -75,7 +75,10 @@ def parse_date(s): if m: # FIXME: add actual timezone support # this just drops the timezone info - notz = m.groups()[0] + notz, ms, tz = m.groups() + if not ms: + ms = '.0' + notz = notz + ms return datetime.strptime(notz, ISO8601) return s