From a65a35f011e1f4ea2a5ea1543309c01fd04c5079 Mon Sep 17 00:00:00 2001 From: Paul Franklin Date: Wed, 8 Jul 2015 10:12:08 -0700 Subject: [PATCH] fix date parser for y-m-d locales (e.g. Hungarian) --- gramps/gen/datehandler/_dateparser.py | 49 +++++++++++++++++++-------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/gramps/gen/datehandler/_dateparser.py b/gramps/gen/datehandler/_dateparser.py index cfeef2214..104ce1872 100644 --- a/gramps/gen/datehandler/_dateparser.py +++ b/gramps/gen/datehandler/_dateparser.py @@ -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,22 +528,38 @@ class DateParser(object): match = regex2.match(text.lower()) if match: groups = match.groups() - 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 + if self.ymd: + if groups[3] is None: + m = 0 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 + 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) if check and not check((d, m, y)): value = Date.EMPTY @@ -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])