diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 65e76a5dc..8dbb39910 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,4 +1,5 @@ 2004-10-10 Don Allingham + * src/DateParser.py: try to detect illegal numerical dates * src/GrampsInMemDB.py: handle null handle * src/GrampsXMLDB.py: disable undo during normal read of database * src/ReadGedcom.py: handle lines shorter than 50 lines, disable undo during @@ -6,6 +7,8 @@ * src/ReadXML.py: disable undo during normal read of databas * src/RelLib.py: revert Name.__cmp__ to Name.is_equal * src/docgen/HTMLDoc.py: drop deprecated gnome.ui dialogs + * src/Utils.py: not_too_old moved over from RelLib.py + * src/WriteGedcom.py: fix call to probably_alive 2004-10-10 Eero Tamminen * TestPlan.txt: Add test for reports like in stable version diff --git a/gramps2/src/DateParser.py b/gramps2/src/DateParser.py index f87e200b3..177d02b1f 100644 --- a/gramps2/src/DateParser.py +++ b/gramps2/src/DateParser.py @@ -337,7 +337,10 @@ class DateParser: y = self._get_int(groups[0]) m = self._get_int(groups[1]) d = self._get_int(groups[2]) - return (d,m,y,False) + if gregorian_valid((d,m)): + return (d,m,y,False) + else: + return Date.EMPTY match = self._rfc.match(text) if match: @@ -345,7 +348,10 @@ class DateParser: d = self._get_int(groups[2]) m = self._rfc_mons_to_int[groups[3]] y = self._get_int(groups[4]) - return (d,m,y,False) + if gregorian_valid((d,m)): + return (d,m,y,False) + else: + return Date.EMPTY match = self._numeric.match(text) if match: @@ -353,7 +359,10 @@ class DateParser: m = self._get_int(groups[1]) d = self._get_int(groups[3]) y = self._get_int(groups[4]) - return (d,m,y,False) + if gregorian_valid((d,m)): + return (d,m,y,False) + else: + return Date.EMPTY return Date.EMPTY @@ -451,3 +460,15 @@ class DateParser: new_date = Date.Date() self.set_date(new_date,text) return new_date + +_max_days = [ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ] + +def gregorian_valid(date_tuple): + day = date_tuple[0] + month = date_tuple[1] + valid = True + if month > 12: + valid = False + elif day > _max_days[month]: + valid = False + return valid diff --git a/gramps2/src/RelLib.py b/gramps2/src/RelLib.py index 60704cc9a..a2219bf80 100644 --- a/gramps2/src/RelLib.py +++ b/gramps2/src/RelLib.py @@ -2243,8 +2243,3 @@ class GenderStats: return Person.unknown -def not_too_old(date): - time_struct = time.localtime(time.time()) - current_year = time_struct[0] - year = date.get_year() - return not( year != 0 and current_year - year > 110) diff --git a/gramps2/src/Utils.py b/gramps2/src/Utils.py index 0627267e9..cf236605f 100644 --- a/gramps2/src/Utils.py +++ b/gramps2/src/Utils.py @@ -45,6 +45,7 @@ import gnome import const import RelImage import GrampsMime +import Date #------------------------------------------------------------------------- # @@ -664,6 +665,12 @@ def probably_alive(person,db): return False return True +def not_too_old(date): + time_struct = time.localtime(time.time()) + current_year = time_struct[0] + year = date.get_year() + return not( year != 0 and current_year - year > 110) + #------------------------------------------------------------------------- # # diff --git a/gramps2/src/WriteGedcom.py b/gramps2/src/WriteGedcom.py index 34966d181..9983a72a8 100644 --- a/gramps2/src/WriteGedcom.py +++ b/gramps2/src/WriteGedcom.py @@ -51,6 +51,8 @@ import Date import GedcomInfo import Errors import ansel_utf8 +import Utils +import Date from gettext import gettext as _ from QuestionDialog import ErrorDialog @@ -750,7 +752,7 @@ class GedcomWriter: def write_person(self,person): self.writeln("0 @%s@ INDI" % person.get_gramps_id()) - restricted = self.restrict and probably_alive (person,self.db) + restricted = self.restrict and Utils.probably_alive (person,self.db) self.prefn(person) primaryname = person.get_primary_name () if restricted and self.living: