diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index cbb1a1863..a5a60ca57 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -7,6 +7,8 @@ variants of month names for parser * src/Date.py: Raise Exception.DateError on invalid arguments + * src/DateParser.py: Catch DateError and use text only date as fallback + * src/plugins/TestcaseGenerator.py: Handle DateError exception 2005-05-12 Don Allingham * src/GrampsBSDDB.py: force database sync on transaction commit diff --git a/gramps2/src/DateParser.py b/gramps2/src/DateParser.py index 1a34d481f..891099043 100644 --- a/gramps2/src/DateParser.py +++ b/gramps2/src/DateParser.py @@ -44,7 +44,7 @@ import calendar # #------------------------------------------------------------------------- import Date - +from Errors import DateError #------------------------------------------------------------------------- # # Top-level module functions @@ -587,5 +587,8 @@ class DateParser: Parses the text, returning a Date object. """ new_date = Date.Date() - self.set_date(new_date,text) + try: + self.set_date(new_date,text) + except DateError: + new_date.set_as_text(text) return new_date diff --git a/gramps2/src/plugins/TestcaseGenerator.py b/gramps2/src/plugins/TestcaseGenerator.py index 404b9cbbb..1223c4b42 100644 --- a/gramps2/src/plugins/TestcaseGenerator.py +++ b/gramps2/src/plugins/TestcaseGenerator.py @@ -420,19 +420,25 @@ class TestcaseGenerator: # test invalid dates dateval = (4,7,1789,False,5,8,1876,False) for l in range(1,len(dateval)): + d = Date.Date() try: - d = Date.Date() d.set(Date.QUAL_NONE,Date.MOD_NONE,Date.CAL_GREGORIAN,dateval[:l],"Text comment") dates.append( d) + except Errors.DateError, e: + d.set_as_text("Date identified value correctly as invalid.\n%s" % e) + dates.append( d) except: d = Date.Date() d.set_as_text("Date.set Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),)) dates.append( d) for l in range(1,len(dateval)): + d = Date.Date() try: - d = Date.Date() d.set(Date.QUAL_NONE,Date.MOD_SPAN,Date.CAL_GREGORIAN,dateval[:l],"Text comment") dates.append( d) + except Errors.DateError, e: + d.set_as_text("Date identified value correctly as invalid.\n%s" % e) + dates.append( d) except: d = Date.Date() d.set_as_text("Date.set Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),))