fix date parser for y-m-d locales (e.g. Hungarian)

This commit is contained in:
Paul Franklin 2015-07-08 10:12:08 -07:00
parent 00a547b2bd
commit a65a35f011

View File

@ -350,6 +350,7 @@ class DateParser(object):
match.groups() == ('d', 'b', 'y')) match.groups() == ('d', 'b', 'y'))
self.ymd = (match.groups() == ('y', 'm', 'd') or \ self.ymd = (match.groups() == ('y', 'm', 'd') or \
match.groups() == ('y', 'b', 'd')) match.groups() == ('y', 'b', 'd'))
# note ('m','d','y') is valid -- in which case both will be False
else: else:
self.dmy = True self.dmy = True
self.ymd = False self.ymd = False
@ -527,22 +528,38 @@ class DateParser(object):
match = regex2.match(text.lower()) match = regex2.match(text.lower())
if match: if match:
groups = match.groups() groups = match.groups()
if groups[1] is None: if self.ymd:
m = 0 if groups[3] is None:
else: m = 0
m = mmap[groups[1].lower()]
d = self._get_int(groups[0])
if groups[2] is None:
y = None
s = False
else:
if groups[4] is not None: # slash year digit
y = int(groups[3]) + 1 # fullyear + 1
s = True
else: else:
y = int(groups[3]) m = mmap[groups[3].lower()]
d = self._get_int(groups[4])
if groups[0] is None:
y = None
s = False s = False
else:
if groups[2] is not None: # slash year digit
y = int(groups[1]) + 1 # fullyear + 1
s = True
else: # regular, non-slash year
y = int(groups[1])
s = False
else:
if groups[1] is None:
m = 0
else:
m = mmap[groups[1].lower()]
d = self._get_int(groups[0])
if groups[2] is None:
y = None
s = False
else:
if groups[4] is not None: # slash year digit
y = int(groups[3]) + 1 # fullyear + 1
s = True
else: # regular, non-slash year
y = int(groups[3])
s = False
value = (d, m, y, s) value = (d, m, y, s)
if check and not check((d, m, y)): if check and not check((d, m, y)):
value = Date.EMPTY value = Date.EMPTY
@ -622,6 +639,10 @@ class DateParser(object):
y = self._get_int(groups[4]) y = self._get_int(groups[4])
m = 0 m = 0
d = 0 d = 0
elif groups[3] is None:
y = self._get_int(groups[1])
m = self._get_int(groups[4])
d = 0
else: else:
y = self._get_int(groups[1]) y = self._get_int(groups[1])
m = self._get_int(groups[3]) m = self._get_int(groups[3])