* src/DateParser.py: Catch DateError and use text only date as fallback

* src/plugins/TestcaseGenerator.py: Handle DateError exception


svn: r4582
This commit is contained in:
Martin Hawlisch 2005-05-13 12:53:00 +00:00
parent dffb9781b3
commit 28023ba12e
3 changed files with 15 additions and 4 deletions

View File

@ -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 <don@gramps-project.org>
* src/GrampsBSDDB.py: force database sync on transaction commit

View File

@ -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

View File

@ -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())),))