Fix ISO date parsing fallback.

Closes issue #194
This commit is contained in:
Lance Stout 2012-08-12 22:35:42 -07:00
parent f7a710e55b
commit 779c258e27

View file

@ -166,32 +166,34 @@ except:
(?P<month>[0-9]{2})?(?P=ymdsep)? (?P<month>[0-9]{2})?(?P=ymdsep)?
(?P<day> [0-9]{2})? (?P<day> [0-9]{2})?
(?: # time part... optional... at least hour must be specified (?P<time>
(?:T|\s+)? (?: # time part... optional... at least hour must be specified
(?P<hour>[0-9]{2}) (?:T|\s+)?
(?: (?P<hour>[0-9]{2})
# minutes, separated with :, or none, from hours
(?P<hmssep>[:]?)
(?P<minute>[0-9]{2})
(?: (?:
# same for seconds, separated with :, or none, from hours # minutes, separated with :, or none, from hours
(?P=hmssep) (?P<hmssep>[:]?)
(?P<second>[0-9]{2}) (?P<minute>[0-9]{2})
(?:
# same for seconds, separated with :, or none, from hours
(?P=hmssep)
(?P<second>[0-9]{2})
)?
)? )?
)?
# fractions # fractions
(?: [,.] (?P<frac>[0-9]{1,10}))? (?: [,.] (?P<frac>[0-9]{1,10}))?
# timezone, Z, +-hh or +-hh:?mm. MUST BE, but complain if not there. # timezone, Z, +-hh or +-hh:?mm. MUST BE, but complain if not there.
( (
(?P<tzempty>Z) (?P<tzempty>Z)
| |
(?P<tzh>[+-][0-9]{2}) (?P<tzh>[+-][0-9]{2})
(?: :? # optional separator (?: :? # optional separator
(?P<tzm>[0-9]{2}) (?P<tzm>[0-9]{2})
)?
)? )?
)? )
)? )?
$ $
""", re.X) # """ """, re.X) # """
@ -211,13 +213,16 @@ except:
for key in vals: for key in vals:
if vals[key] is None: if vals[key] is None:
vals[key] = def_vals.get(key, 0) vals[key] = def_vals.get(key, 0)
elif key not in ['ymdsep', 'hmssep', 'tzempty']: elif key not in ['time', 'ymdsep', 'hmssep', 'tzempty']:
vals[key] = int(vals[key]) vals[key] = int(vals[key])
year = vals['year'] year = vals['year']
month = vals['month'] month = vals['month']
day = vals['day'] day = vals['day']
if m.group('time') is None:
return datetime.date(year, month, day)
h, min, s, us = None, None, None, 0 h, min, s, us = None, None, None, 0
frac = 0 frac = 0
if m.group('tzempty') == None and m.group('tzh') == None: if m.group('tzempty') == None and m.group('tzh') == None: