Clean up some date related problems.
svn: r622
This commit is contained in:
parent
fc8c83168d
commit
751a00162e
@ -153,14 +153,27 @@ class Date:
|
|||||||
def getYear(self):
|
def getYear(self):
|
||||||
return self.start.year
|
return self.start.year
|
||||||
|
|
||||||
|
def getYearValid(self):
|
||||||
|
return self.start.year != UNDEF
|
||||||
|
|
||||||
def getMonth(self):
|
def getMonth(self):
|
||||||
if self.start.month == UNDEF:
|
if self.start.month == UNDEF:
|
||||||
return UNDEF
|
return UNDEF
|
||||||
return self.start.month+1
|
return self.start.month+1
|
||||||
|
|
||||||
|
def getMonthValid(self):
|
||||||
|
return self.start.month != UNDEF
|
||||||
|
|
||||||
def getDay(self):
|
def getDay(self):
|
||||||
return self.start.day
|
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):
|
def getStopYear(self):
|
||||||
if self.stop == None:
|
if self.stop == None:
|
||||||
self.stop = SingleDate()
|
self.stop = SingleDate()
|
||||||
@ -407,18 +420,31 @@ class SingleDate:
|
|||||||
return UNDEF
|
return UNDEF
|
||||||
return self.month + 1
|
return self.month + 1
|
||||||
|
|
||||||
|
def getMonthValid(self):
|
||||||
|
return self.month != UNDEF
|
||||||
|
|
||||||
def setDay(self,val):
|
def setDay(self,val):
|
||||||
self.day = val
|
self.day = val
|
||||||
|
|
||||||
def getDay(self):
|
def getDay(self):
|
||||||
return self.day
|
return self.day
|
||||||
|
|
||||||
|
def getDayValid(self):
|
||||||
|
return self.day != UNDEF
|
||||||
|
|
||||||
def setYear(self,val):
|
def setYear(self,val):
|
||||||
self.year = val
|
self.year = val
|
||||||
|
|
||||||
def getYear(self):
|
def getYear(self):
|
||||||
return self.year
|
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):
|
def setMonthStr(self,text):
|
||||||
try:
|
try:
|
||||||
self.month = _m2num[string.lower(text[0:3])]
|
self.month = _m2num[string.lower(text[0:3])]
|
||||||
|
@ -622,7 +622,7 @@ def date_match(date1,date2):
|
|||||||
if date1.getYear() == date2.getYear():
|
if date1.getYear() == date2.getYear():
|
||||||
if date1.getMonth() == date2.getMonth():
|
if date1.getMonth() == date2.getMonth():
|
||||||
return 0.75
|
return 0.75
|
||||||
if date1.getMonth() == -1 or date2.getMonth() == -1:
|
if not date1.getMonthValid() or not date2.getMonthValid():
|
||||||
return 0.75
|
return 0.75
|
||||||
else:
|
else:
|
||||||
return -1
|
return -1
|
||||||
|
@ -108,9 +108,6 @@ class SelectChild:
|
|||||||
bday = self.person.getBirth().getDateObj()
|
bday = self.person.getBirth().getDateObj()
|
||||||
dday = self.person.getDeath().getDateObj()
|
dday = self.person.getDeath().getDateObj()
|
||||||
|
|
||||||
bday_valid = (bday.getYear() != -1)
|
|
||||||
dday_valid = (dday.getYear() != -1)
|
|
||||||
|
|
||||||
slist = []
|
slist = []
|
||||||
for f in [self.person.getMainFamily()] + self.person.getFamilyList():
|
for f in [self.person.getMainFamily()] + self.person.getFamilyList():
|
||||||
if f:
|
if f:
|
||||||
@ -132,8 +129,8 @@ class SelectChild:
|
|||||||
pdday = person.getDeath().getDateObj()
|
pdday = person.getDeath().getDateObj()
|
||||||
pbday = person.getBirth().getDateObj()
|
pbday = person.getBirth().getDateObj()
|
||||||
|
|
||||||
if bday_valid:
|
if bday.getYearValid():
|
||||||
if pbday.getYear() != -1:
|
if pbday.getYearValid():
|
||||||
|
|
||||||
# reject if child birthdate < parents birthdate + 10
|
# reject if child birthdate < parents birthdate + 10
|
||||||
if pbday.getLowYear() < bday.getHighYear()+10:
|
if pbday.getLowYear() < bday.getHighYear()+10:
|
||||||
@ -143,19 +140,19 @@ class SelectChild:
|
|||||||
if pbday.getLowYear() > bday.getHighYear()+90:
|
if pbday.getLowYear() > bday.getHighYear()+90:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if pdday.getYear() != -1:
|
if pdday.getYearValid():
|
||||||
# reject if child deathdate < parents birthdate+ 10
|
# reject if child deathdate < parents birthdate+ 10
|
||||||
if pdday.getLowYear() < bday.getHighYear()+10:
|
if pdday.getLowYear() < bday.getHighYear()+10:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if dday_valid:
|
if dday.getYearValid():
|
||||||
if pbday.getYear() != -1:
|
if pbday.getYearValid():
|
||||||
|
|
||||||
# reject if childs birth date > parents deathday + 3
|
# reject if childs birth date > parents deathday + 3
|
||||||
if pdday.getLowYear() > dday.getHighYear()+3:
|
if pdday.getLowYear() > dday.getHighYear()+3:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if pdday.getYear() != -1:
|
if pdday.getYearValid():
|
||||||
|
|
||||||
# reject if childs death date > parents deathday + 150
|
# reject if childs death date > parents deathday + 150
|
||||||
if pbday.getLowYear() > dday.getHighYear() + 150:
|
if pbday.getLowYear() > dday.getHighYear() + 150:
|
||||||
|
@ -173,7 +173,7 @@ class AncestorReport:
|
|||||||
place = place[:-1]
|
place = place[:-1]
|
||||||
if date.getDate() != "" or place != "":
|
if date.getDate() != "" or place != "":
|
||||||
if date.getDate() != "":
|
if date.getDate() != "":
|
||||||
if date.getDay() != -1 and date.getMonth() != -1:
|
if date.getDayValid() and date.getMonthValid():
|
||||||
if place != "":
|
if place != "":
|
||||||
t = _("%s was born on %s in %s. ") % \
|
t = _("%s was born on %s in %s. ") % \
|
||||||
(name,date.getDate(),place)
|
(name,date.getDate(),place)
|
||||||
@ -207,7 +207,7 @@ class AncestorReport:
|
|||||||
male = 0
|
male = 0
|
||||||
|
|
||||||
if date.getDate() != "":
|
if date.getDate() != "":
|
||||||
if date.getDay() != -1 and date.getMonth() != -1:
|
if date.getDayValid() and date.getMonthValid():
|
||||||
if male:
|
if male:
|
||||||
if place != "":
|
if place != "":
|
||||||
t = _("He died on %s in %s") % \
|
t = _("He died on %s in %s") % \
|
||||||
@ -243,7 +243,7 @@ class AncestorReport:
|
|||||||
place = place[:-1]
|
place = place[:-1]
|
||||||
if date.getDate() != "" or place != "":
|
if date.getDate() != "" or place != "":
|
||||||
if date.getDate() != "":
|
if date.getDate() != "":
|
||||||
if date.getDay() != -1 and date.getMonth() != -1:
|
if date.getDayValid() and date.getMonthValid():
|
||||||
if place != "":
|
if place != "":
|
||||||
t = _(", and was buried on %s in %s.") % \
|
t = _(", and was buried on %s in %s.") % \
|
||||||
(date.getDate(),place)
|
(date.getDate(),place)
|
||||||
|
@ -71,6 +71,24 @@ class DescendantReport:
|
|||||||
def end(self):
|
def end(self):
|
||||||
self.doc.close()
|
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")
|
self.doc.start_paragraph("Title")
|
||||||
name = self.person.getPrimaryName().getRegularName()
|
name = self.person.getPrimaryName().getRegularName()
|
||||||
self.doc.write_text(_("Descendants of %s") % name)
|
self.doc.write_text(_("Descendants of %s") % name)
|
||||||
|
self.dump_dates(self.person)
|
||||||
self.doc.end_paragraph()
|
self.doc.end_paragraph()
|
||||||
self.dump(0,self.person)
|
self.dump(0,self.person)
|
||||||
|
|
||||||
@ -94,18 +113,7 @@ class DescendantReport:
|
|||||||
self.doc.start_paragraph("Level" + str(level))
|
self.doc.start_paragraph("Level" + str(level))
|
||||||
self.doc.write_text(str(level) + '. ')
|
self.doc.write_text(str(level) + '. ')
|
||||||
self.doc.write_text(person.getPrimaryName().getRegularName())
|
self.doc.write_text(person.getPrimaryName().getRegularName())
|
||||||
|
self.dump_dates(person)
|
||||||
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.doc.end_paragraph()
|
self.doc.end_paragraph()
|
||||||
|
|
||||||
childlist = []
|
childlist = []
|
||||||
|
@ -127,9 +127,9 @@ class DetAncestorReport:
|
|||||||
def write_children(self, family):
|
def write_children(self, family):
|
||||||
""" List children """
|
""" List children """
|
||||||
|
|
||||||
print "family: ", family.__dict__
|
#print "family: ", family.__dict__
|
||||||
num_children= len(family.getChildList())
|
num_children= len(family.getChildList())
|
||||||
print "Children= ", len(family.getChildList())
|
#print "Children= ", len(family.getChildList())
|
||||||
if num_children > 0:
|
if num_children > 0:
|
||||||
self.doc.start_paragraph("ChildTitle")
|
self.doc.start_paragraph("ChildTitle")
|
||||||
mother= family.getMother().getPrimaryName().getRegularName()
|
mother= family.getMother().getPrimaryName().getRegularName()
|
||||||
@ -220,7 +220,7 @@ class DetAncestorReport:
|
|||||||
else: place= ""
|
else: place= ""
|
||||||
|
|
||||||
if date.getDate() != "":
|
if date.getDate() != "":
|
||||||
if date.getDay() != -1 and date.getMonth() != -1 and \
|
if date.getDayValid() and date.getMonthValid() and \
|
||||||
rptOptions.fullDate == reportOptions.Yes:
|
rptOptions.fullDate == reportOptions.Yes:
|
||||||
if place != "":
|
if place != "":
|
||||||
self.doc.write_text(" was born on %s in %s." % (date.getDate(), place))
|
self.doc.write_text(" was born on %s in %s." % (date.getDate(), place))
|
||||||
@ -296,7 +296,7 @@ class DetAncestorReport:
|
|||||||
place = place[:-1]
|
place = place[:-1]
|
||||||
fulldate= ""
|
fulldate= ""
|
||||||
if date.getDate() != "":
|
if date.getDate() != "":
|
||||||
if date.getDay() != -1 and date.getMonth() != -1 and \
|
if date.getDayValid() and date.getMonthValid() and \
|
||||||
rptOptions.fullDate == reportOptions.Yes:
|
rptOptions.fullDate == reportOptions.Yes:
|
||||||
fulldate= date.getDate()
|
fulldate= date.getDate()
|
||||||
elif rptOptions.blankDate == reportOptions.Yes:
|
elif rptOptions.blankDate == reportOptions.Yes:
|
||||||
@ -375,8 +375,8 @@ class DetAncestorReport:
|
|||||||
date= marriage.getDateObj()
|
date= marriage.getDateObj()
|
||||||
fulldate= ""
|
fulldate= ""
|
||||||
if date != None:
|
if date != None:
|
||||||
if date.getYear() != -1:
|
if date.getYearValid():
|
||||||
if date.getDay() != -1 and date.getMonth() != -1 and \
|
if date.getDayValid() and date.getMonthValid() and \
|
||||||
rptOptions.fullDate == reportOptions.Yes:
|
rptOptions.fullDate == reportOptions.Yes:
|
||||||
fulldate= date.getDate()
|
fulldate= date.getDate()
|
||||||
elif rptOptions.blankDate == reportOptions.Yes:
|
elif rptOptions.blankDate == reportOptions.Yes:
|
||||||
@ -790,13 +790,13 @@ class reportOptions:
|
|||||||
#print "birth=", birth.__dict__
|
#print "birth=", birth.__dict__
|
||||||
#print "death=", death.__dict__
|
#print "death=", death.__dict__
|
||||||
self.t= ""
|
self.t= ""
|
||||||
if birth.getYear() != -1 and death.getYear() != -1:
|
if birth.getYearValid() and death.getYearValid():
|
||||||
self.age= death.getYear() - birth.getYear()
|
self.age= death.getYear() - birth.getYear()
|
||||||
self.units= "year"
|
self.units= "year"
|
||||||
if birth.getMonth() != -1 and death.getMonth() != -1:
|
if birth.getMonthValid() and death.getMonthValid():
|
||||||
if birth.getMonth() > death.getMonth():
|
if birth.getMonth() > death.getMonth():
|
||||||
self.age= self.age -1
|
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():
|
if birth.getMonth() == death.getMonth() and birth.getDay() > death.getDay():
|
||||||
self.age= self.age -1
|
self.age= self.age -1
|
||||||
self.units= "month"
|
self.units= "month"
|
||||||
|
@ -334,7 +334,7 @@ class Merge:
|
|||||||
if date1.getYear() == date2.getYear():
|
if date1.getYear() == date2.getYear():
|
||||||
if date1.getMonth() == date2.getMonth():
|
if date1.getMonth() == date2.getMonth():
|
||||||
return 0.75
|
return 0.75
|
||||||
if date1.getMonth() == -1 or date2.getMonth() == -1:
|
if not date1.getMonthValid() or not date2.getMonthValid():
|
||||||
return 0.75
|
return 0.75
|
||||||
else:
|
else:
|
||||||
return -1
|
return -1
|
||||||
|
@ -687,10 +687,10 @@ def probably_alive(person):
|
|||||||
if death.getDate() != "":
|
if death.getDate() != "":
|
||||||
return 0
|
return 0
|
||||||
if birth.getDate() != "":
|
if birth.getDate() != "":
|
||||||
year = birth.getDateObj().get_start_date().getYear()
|
year = birth.getDateObj().get_start_date()
|
||||||
time_struct = time.localtime(time.time())
|
time_struct = time.localtime(time.time())
|
||||||
current_year = time_struct[0]
|
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 0
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
@ -267,19 +267,22 @@ def make_date(subdate,mmap):
|
|||||||
mon = subdate.getMonth()
|
mon = subdate.getMonth()
|
||||||
year = subdate.getYear()
|
year = subdate.getYear()
|
||||||
mode = subdate.getModeVal()
|
mode = subdate.getModeVal()
|
||||||
|
day_valid = subdate.getDayValid()
|
||||||
|
mon_valid = subdate.getMonthValid()
|
||||||
|
year_valid = subdate.getYearValid()
|
||||||
|
|
||||||
if day == Date.UNDEF:
|
if not day_valid:
|
||||||
if mon == Date.UNDEF:
|
if not mon_valid:
|
||||||
retval = str(year)
|
retval = str(year)
|
||||||
elif year == Date.UNDEF:
|
elif not year_valid:
|
||||||
retval = mmap[mon]
|
retval = mmap[mon]
|
||||||
else:
|
else:
|
||||||
retval = "%s %d" % (mmap[mon],year)
|
retval = "%s %d" % (mmap[mon],year)
|
||||||
elif mon == Date.UNDEF:
|
elif not mon_valid:
|
||||||
retval = str(year)
|
retval = str(year)
|
||||||
else:
|
else:
|
||||||
month = mmap[mon]
|
month = mmap[mon]
|
||||||
if year == Date.UNDEF:
|
if not year_valid:
|
||||||
retval = "%d %s ????" % (day,month)
|
retval = "%d %s ????" % (day,month)
|
||||||
else:
|
else:
|
||||||
retval = "%d %s %d" % (day,month,year)
|
retval = "%d %s %d" % (day,month,year)
|
||||||
@ -324,20 +327,20 @@ def gedcom_date(date):
|
|||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
def ged_subdate(date):
|
def ged_subdate(date):
|
||||||
|
|
||||||
if date.month == -1 and date.day == -1 and date.year == -1 :
|
if not date.getValid():
|
||||||
return ""
|
return ""
|
||||||
elif date.day == -1:
|
elif not date.getDayValid():
|
||||||
if date.month == -1:
|
if not date.getMonthValid():
|
||||||
retval = str(date.year)
|
retval = str(date.year)
|
||||||
elif date.year == -1:
|
elif not date.getYearValid():
|
||||||
retval = "(%s)" % Date.SingleDate.emname[date.month]
|
retval = "(%s)" % Date.SingleDate.emname[date.month]
|
||||||
else:
|
else:
|
||||||
retval = "%s %d" % (Date.SingleDate.emname[date.month],date.year)
|
retval = "%s %d" % (Date.SingleDate.emname[date.month],date.year)
|
||||||
elif date.month == -1:
|
elif not date.getMonthValid():
|
||||||
retval = str(date.year)
|
retval = str(date.year)
|
||||||
else:
|
else:
|
||||||
month = Date.SingleDate.emname[date.month]
|
month = Date.SingleDate.emname[date.month]
|
||||||
if date.year == -1:
|
if not date.getYearValid():
|
||||||
retval = "(%d %s)" % (date.day,month)
|
retval = "(%d %s)" % (date.day,month)
|
||||||
else:
|
else:
|
||||||
retval = "%d %s %d" % (date.day,month,date.year)
|
retval = "%d %s %d" % (date.day,month,date.year)
|
||||||
@ -989,10 +992,10 @@ class GedcomWriter:
|
|||||||
if death.getDate() != "":
|
if death.getDate() != "":
|
||||||
return 0
|
return 0
|
||||||
if birth.getDate() != "":
|
if birth.getDate() != "":
|
||||||
year = birth.getDateObj().getYear()
|
year = birth.getDateObj()
|
||||||
time_struct = time.localtime(time.time())
|
time_struct = time.localtime(time.time())
|
||||||
current_year = time_struct[0]
|
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 0
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
@ -279,10 +279,10 @@ def probably_alive(person):
|
|||||||
if death.getDate() != "":
|
if death.getDate() != "":
|
||||||
return 0
|
return 0
|
||||||
if birth.getDate() != "":
|
if birth.getDate() != "":
|
||||||
year = birth.getDateObj().getYear()
|
year = birth.getDateObj()
|
||||||
time_struct = time.localtime(time.time())
|
time_struct = time.localtime(time.time())
|
||||||
current_year = time_struct[0]
|
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 0
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user