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'))
self.ymd = (match.groups() == ('y', 'm', 'd') or \
match.groups() == ('y', 'b', 'd'))
# note ('m','d','y') is valid -- in which case both will be False
else:
self.dmy = True
self.ymd = False
@ -527,12 +528,28 @@ class DateParser(object):
match = regex2.match(text.lower())
if match:
groups = match.groups()
if self.ymd:
if groups[3] is None:
m = 0
else:
m = mmap[groups[3].lower()]
d = self._get_int(groups[4])
if groups[0] is None:
y = None
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
@ -540,7 +557,7 @@ class DateParser(object):
if groups[4] is not None: # slash year digit
y = int(groups[3]) + 1 # fullyear + 1
s = True
else:
else: # regular, non-slash year
y = int(groups[3])
s = False
value = (d, m, y, s)
@ -622,6 +639,10 @@ class DateParser(object):
y = self._get_int(groups[4])
m = 0
d = 0
elif groups[3] is None:
y = self._get_int(groups[1])
m = self._get_int(groups[4])
d = 0
else:
y = self._get_int(groups[1])
m = self._get_int(groups[3])