diff --git a/gramps2/src/Calendar.py b/gramps2/src/Calendar.py index a7f4e9a2a..581d19135 100644 --- a/gramps2/src/Calendar.py +++ b/gramps2/src/Calendar.py @@ -30,6 +30,7 @@ __version__ = "$Revision$" from intl import gettext as _ import re +import Errors #------------------------------------------------------------------------- # @@ -66,7 +67,6 @@ fmt3 = re.compile(_start+r"([?\d]+)\s*[./-]\s*([?\d]+)\s*[./-]\s*([?\d]+)\s*$", fmt7 = re.compile(_start+r"([?\d]+)\s*[./-]\s*([?\d]+)\s*$", re.IGNORECASE) fmt4 = re.compile(_start+"(\S+)\s+(\d+)\s*$", re.IGNORECASE) fmt5 = re.compile(_start+"(\d+)\s*$", re.IGNORECASE) -fmt6 = re.compile(_start+"(\S+)\s*$", re.IGNORECASE) #------------------------------------------------------------------------- @@ -440,10 +440,11 @@ class Calendar: matches = match.groups() mode = self.set_mode_value(matches[0]) month = self.set_month_string(matches[2]) - day = self.set_value(matches[1]) - if len(matches) == 4 and matches[3] != None: - year = self.set_value(matches[3]) - return (year,month,day,mode) + if month != UNDEF: + day = self.set_value(matches[1]) + if len(matches) == 4 and matches[3] != None: + year = self.set_value(matches[3]) + return (year,month,day,mode) match = fmt5.match(text) if match != None: @@ -487,28 +488,24 @@ class Calendar: matches = match.groups() mode = self.set_mode_value(matches[0]) month = self.set_month_string(unicode(matches[1])) - if matches[2]: - val = matches[2].replace(',','') - day = self.set_value(val) - year = self.set_value(matches[3]) - return (year,month,day,mode) + if month != UNDEF: + if matches[2]: + val = matches[2].replace(',','') + day = self.set_value(val) + year = self.set_value(matches[3]) + return (year,month,day,mode) match = fmt4.match(text) if match != None: matches = match.groups() mode = self.set_mode_value(matches[0]) month = self.set_month_string(unicode(matches[1])) - if len(matches) == 4: - year = self.set_value(matches[3]) - return (year,month,day,mode) + if month != UNDEF: + if len(matches) == 4: + year = self.set_value(matches[3]) + return (year,month,day,mode) - match = fmt6.match(text) - if match != None: - matches = match.groups() - mode = self.set_mode_value(matches[0]) - month = self.set_value(matches[1]) - - return (year,month,day,mode) + raise Errors.DateError _FMT_FUNC = [ @@ -550,5 +547,3 @@ def calendar_names(): list.append(n) list.sort() return list - - diff --git a/gramps2/src/Date.py b/gramps2/src/Date.py index 35ee4b92d..c6aefd734 100644 --- a/gramps2/src/Date.py +++ b/gramps2/src/Date.py @@ -42,6 +42,7 @@ import Gregorian import Julian import Hebrew import FrenchRepublic +import Errors from intl import gettext as _ @@ -71,8 +72,6 @@ class Date: """ formatCode = 0 - Error = "Illegal Date" - fstr = _("(from|between|bet|bet.)") tstr = _("(and|to|-)") @@ -207,7 +206,7 @@ class Date: else: self.start.set(text) self.range = 0 - except Date.Error: + except Errors.DateError: if text != "": self.range = -1 self.text = text diff --git a/gramps2/src/Errors.py b/gramps2/src/Errors.py index 04eaa9bf3..80a799103 100644 --- a/gramps2/src/Errors.py +++ b/gramps2/src/Errors.py @@ -18,6 +18,15 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # +class DateError(Exception): + """Error used to report Date errors""" + def __init__(self,value=""): + Exception.__init__(self) + self.value = value + + def __str__(self): + return self.value + class ReportError(Exception): """Error used to report Report errors""" def __init__(self,value,value2=""):