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,12 +528,28 @@ class DateParser(object):
match = regex2.match(text.lower()) match = regex2.match(text.lower())
if match: if match:
groups = match.groups() 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: if groups[1] is None:
m = 0 m = 0
else: else:
m = mmap[groups[1].lower()] m = mmap[groups[1].lower()]
d = self._get_int(groups[0]) d = self._get_int(groups[0])
if groups[2] is None: if groups[2] is None:
y = None y = None
s = False s = False
@ -540,7 +557,7 @@ class DateParser(object):
if groups[4] is not None: # slash year digit if groups[4] is not None: # slash year digit
y = int(groups[3]) + 1 # fullyear + 1 y = int(groups[3]) + 1 # fullyear + 1
s = True s = True
else: else: # regular, non-slash year
y = int(groups[3]) y = int(groups[3])
s = False s = False
value = (d, m, y, s) value = (d, m, y, s)
@ -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])