Clean up some date related problems.

svn: r622
This commit is contained in:
David Hampton 2001-12-16 02:21:05 +00:00
parent fc8c83168d
commit 751a00162e
10 changed files with 86 additions and 52 deletions

View File

@ -153,14 +153,27 @@ class Date:
def getYear(self):
return self.start.year
def getYearValid(self):
return self.start.year != UNDEF
def getMonth(self):
if self.start.month == UNDEF:
return UNDEF
return self.start.month+1
def getMonthValid(self):
return self.start.month != UNDEF
def getDay(self):
return self.start.day
def getDayValid(self):
return self.start.day != UNDEF
def getValid(self):
""" Returns true if any part of the date is valid"""
return self.start.year != UNDEF or self.start.month != UNDEF or self.start.day != UNDEF
def getStopYear(self):
if self.stop == None:
self.stop = SingleDate()
@ -407,18 +420,31 @@ class SingleDate:
return UNDEF
return self.month + 1
def getMonthValid(self):
return self.month != UNDEF
def setDay(self,val):
self.day = val
def getDay(self):
return self.day
def getDayValid(self):
return self.day != UNDEF
def setYear(self,val):
self.year = val
def getYear(self):
return self.year
def getYearValid(self):
return self.year != UNDEF
def getValid(self):
""" Returns true if any part of the date is valid"""
return self.year != UNDEF or self.month != UNDEF or self.day != UNDEF
def setMonthStr(self,text):
try:
self.month = _m2num[string.lower(text[0:3])]

View File

@ -622,7 +622,7 @@ def date_match(date1,date2):
if date1.getYear() == date2.getYear():
if date1.getMonth() == date2.getMonth():
return 0.75
if date1.getMonth() == -1 or date2.getMonth() == -1:
if not date1.getMonthValid() or not date2.getMonthValid():
return 0.75
else:
return -1

View File

@ -108,9 +108,6 @@ class SelectChild:
bday = self.person.getBirth().getDateObj()
dday = self.person.getDeath().getDateObj()
bday_valid = (bday.getYear() != -1)
dday_valid = (dday.getYear() != -1)
slist = []
for f in [self.person.getMainFamily()] + self.person.getFamilyList():
if f:
@ -132,8 +129,8 @@ class SelectChild:
pdday = person.getDeath().getDateObj()
pbday = person.getBirth().getDateObj()
if bday_valid:
if pbday.getYear() != -1:
if bday.getYearValid():
if pbday.getYearValid():
# reject if child birthdate < parents birthdate + 10
if pbday.getLowYear() < bday.getHighYear()+10:
@ -143,19 +140,19 @@ class SelectChild:
if pbday.getLowYear() > bday.getHighYear()+90:
continue
if pdday.getYear() != -1:
if pdday.getYearValid():
# reject if child deathdate < parents birthdate+ 10
if pdday.getLowYear() < bday.getHighYear()+10:
continue
if dday_valid:
if pbday.getYear() != -1:
if dday.getYearValid():
if pbday.getYearValid():
# reject if childs birth date > parents deathday + 3
if pdday.getLowYear() > dday.getHighYear()+3:
continue
if pdday.getYear() != -1:
if pdday.getYearValid():
# reject if childs death date > parents deathday + 150
if pbday.getLowYear() > dday.getHighYear() + 150:

View File

@ -173,7 +173,7 @@ class AncestorReport:
place = place[:-1]
if date.getDate() != "" or place != "":
if date.getDate() != "":
if date.getDay() != -1 and date.getMonth() != -1:
if date.getDayValid() and date.getMonthValid():
if place != "":
t = _("%s was born on %s in %s. ") % \
(name,date.getDate(),place)
@ -207,7 +207,7 @@ class AncestorReport:
male = 0
if date.getDate() != "":
if date.getDay() != -1 and date.getMonth() != -1:
if date.getDayValid() and date.getMonthValid():
if male:
if place != "":
t = _("He died on %s in %s") % \
@ -243,7 +243,7 @@ class AncestorReport:
place = place[:-1]
if date.getDate() != "" or place != "":
if date.getDate() != "":
if date.getDay() != -1 and date.getMonth() != -1:
if date.getDayValid() and date.getMonthValid():
if place != "":
t = _(", and was buried on %s in %s.") % \
(date.getDate(),place)

View File

@ -71,6 +71,24 @@ class DescendantReport:
def end(self):
self.doc.close()
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def dump_dates(self, person):
birth = person.getBirth().getDateObj().get_start_date()
death = person.getDeath().getDateObj().get_start_date()
if birth.getYearValid() or death.getYearValid():
self.doc.write_text(' (')
if birth.getYearValid():
self.doc.write_text('b. ' + str(birth.getYear()))
if death.getYearValid():
if birth.getYearValid():
self.doc.write_text(', ')
self.doc.write_text('d. ' + str(death.getYear()))
self.doc.write_text(')')
#--------------------------------------------------------------------
#
#
@ -80,6 +98,7 @@ class DescendantReport:
self.doc.start_paragraph("Title")
name = self.person.getPrimaryName().getRegularName()
self.doc.write_text(_("Descendants of %s") % name)
self.dump_dates(self.person)
self.doc.end_paragraph()
self.dump(0,self.person)
@ -94,18 +113,7 @@ class DescendantReport:
self.doc.start_paragraph("Level" + str(level))
self.doc.write_text(str(level) + '. ')
self.doc.write_text(person.getPrimaryName().getRegularName())
birth = person.getBirth().getDateObj().get_start_date().getYear()
death = person.getDeath().getDateObj().get_start_date().getYear()
if birth != -1 or death != -1:
self.doc.write_text(' (')
if birth != -1:
self.doc.write_text('b. ' + str(birth))
if death != -1:
if birth != -1:
self.doc.write_text(', ')
self.doc.write_text('d. ' + str(death))
self.doc.write_text(')')
self.dump_dates(person)
self.doc.end_paragraph()
childlist = []

View File

@ -127,9 +127,9 @@ class DetAncestorReport:
def write_children(self, family):
""" List children """
print "family: ", family.__dict__
#print "family: ", family.__dict__
num_children= len(family.getChildList())
print "Children= ", len(family.getChildList())
#print "Children= ", len(family.getChildList())
if num_children > 0:
self.doc.start_paragraph("ChildTitle")
mother= family.getMother().getPrimaryName().getRegularName()
@ -220,7 +220,7 @@ class DetAncestorReport:
else: place= ""
if date.getDate() != "":
if date.getDay() != -1 and date.getMonth() != -1 and \
if date.getDayValid() and date.getMonthValid() and \
rptOptions.fullDate == reportOptions.Yes:
if place != "":
self.doc.write_text(" was born on %s in %s." % (date.getDate(), place))
@ -296,7 +296,7 @@ class DetAncestorReport:
place = place[:-1]
fulldate= ""
if date.getDate() != "":
if date.getDay() != -1 and date.getMonth() != -1 and \
if date.getDayValid() and date.getMonthValid() and \
rptOptions.fullDate == reportOptions.Yes:
fulldate= date.getDate()
elif rptOptions.blankDate == reportOptions.Yes:
@ -375,8 +375,8 @@ class DetAncestorReport:
date= marriage.getDateObj()
fulldate= ""
if date != None:
if date.getYear() != -1:
if date.getDay() != -1 and date.getMonth() != -1 and \
if date.getYearValid():
if date.getDayValid() and date.getMonthValid() and \
rptOptions.fullDate == reportOptions.Yes:
fulldate= date.getDate()
elif rptOptions.blankDate == reportOptions.Yes:
@ -790,13 +790,13 @@ class reportOptions:
#print "birth=", birth.__dict__
#print "death=", death.__dict__
self.t= ""
if birth.getYear() != -1 and death.getYear() != -1:
if birth.getYearValid() and death.getYearValid():
self.age= death.getYear() - birth.getYear()
self.units= "year"
if birth.getMonth() != -1 and death.getMonth() != -1:
if birth.getMonthValid() and death.getMonthValid():
if birth.getMonth() > death.getMonth():
self.age= self.age -1
if birth.getDay() != -1 and death.getDay() != -1:
if birth.getDayValid() and death.getDayValid():
if birth.getMonth() == death.getMonth() and birth.getDay() > death.getDay():
self.age= self.age -1
self.units= "month"

View File

@ -334,7 +334,7 @@ class Merge:
if date1.getYear() == date2.getYear():
if date1.getMonth() == date2.getMonth():
return 0.75
if date1.getMonth() == -1 or date2.getMonth() == -1:
if not date1.getMonthValid() or not date2.getMonthValid():
return 0.75
else:
return -1

View File

@ -687,10 +687,10 @@ def probably_alive(person):
if death.getDate() != "":
return 0
if birth.getDate() != "":
year = birth.getDateObj().get_start_date().getYear()
year = birth.getDateObj().get_start_date()
time_struct = time.localtime(time.time())
current_year = time_struct[0]
if year != -1 and current_year - year > 110:
if year.getYearValid() and current_year - year.getYear() > 110:
return 0
return 1

View File

@ -267,19 +267,22 @@ def make_date(subdate,mmap):
mon = subdate.getMonth()
year = subdate.getYear()
mode = subdate.getModeVal()
day_valid = subdate.getDayValid()
mon_valid = subdate.getMonthValid()
year_valid = subdate.getYearValid()
if day == Date.UNDEF:
if mon == Date.UNDEF:
if not day_valid:
if not mon_valid:
retval = str(year)
elif year == Date.UNDEF:
elif not year_valid:
retval = mmap[mon]
else:
retval = "%s %d" % (mmap[mon],year)
elif mon == Date.UNDEF:
elif not mon_valid:
retval = str(year)
else:
month = mmap[mon]
if year == Date.UNDEF:
if not year_valid:
retval = "%d %s ????" % (day,month)
else:
retval = "%d %s %d" % (day,month,year)
@ -324,20 +327,20 @@ def gedcom_date(date):
#-------------------------------------------------------------------------
def ged_subdate(date):
if date.month == -1 and date.day == -1 and date.year == -1 :
if not date.getValid():
return ""
elif date.day == -1:
if date.month == -1:
elif not date.getDayValid():
if not date.getMonthValid():
retval = str(date.year)
elif date.year == -1:
elif not date.getYearValid():
retval = "(%s)" % Date.SingleDate.emname[date.month]
else:
retval = "%s %d" % (Date.SingleDate.emname[date.month],date.year)
elif date.month == -1:
elif not date.getMonthValid():
retval = str(date.year)
else:
month = Date.SingleDate.emname[date.month]
if date.year == -1:
if not date.getYearValid():
retval = "(%d %s)" % (date.day,month)
else:
retval = "%d %s %d" % (date.day,month,date.year)
@ -989,10 +992,10 @@ class GedcomWriter:
if death.getDate() != "":
return 0
if birth.getDate() != "":
year = birth.getDateObj().getYear()
year = birth.getDateObj()
time_struct = time.localtime(time.time())
current_year = time_struct[0]
if year != -1 and current_year - year > 110:
if year.getYearValid() and current_year - year.getYear() > 110:
return 0
return 1

View File

@ -279,10 +279,10 @@ def probably_alive(person):
if death.getDate() != "":
return 0
if birth.getDate() != "":
year = birth.getDateObj().getYear()
year = birth.getDateObj()
time_struct = time.localtime(time.time())
current_year = time_struct[0]
if year != -1 and current_year - year > 110:
if year.getYearValid() and current_year - year.getYear() > 110:
return 0
return 1