7034: probably_alive() failing when no birth-death dates specified; 6965: Probably Alive fails when birth date is a range
svn: r23021
This commit is contained in:
		
							
								
								
									
										11
									
								
								src/Utils.py
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								src/Utils.py
									
									
									
									
									
								
							@@ -600,7 +600,7 @@ class ProbablyAlive(object):
 | 
			
		||||
            if death_ref:
 | 
			
		||||
                death = self.db.get_event_from_handle(death_ref.ref)
 | 
			
		||||
                if death:
 | 
			
		||||
                    if death.get_date_object().get_start_date() != gen.lib.Date.EMPTY:
 | 
			
		||||
                    if death.get_date_object().is_valid():
 | 
			
		||||
                        death_date = death.get_date_object()
 | 
			
		||||
                    else:
 | 
			
		||||
                        death_date = gen.lib.date.Today()
 | 
			
		||||
@@ -614,7 +614,9 @@ class ProbablyAlive(object):
 | 
			
		||||
                    ev = self.db.get_event_from_handle(ev_ref.ref)
 | 
			
		||||
                    if ev and ev.type.is_death_fallback():
 | 
			
		||||
                        death_date = ev.get_date_object()
 | 
			
		||||
                        explain = _("death-related evidence")
 | 
			
		||||
                        if not death_date.is_valid():
 | 
			
		||||
                            death_date = Today() # before today
 | 
			
		||||
                            death_date.set_modifier(Date.MOD_BEFORE)
 | 
			
		||||
 | 
			
		||||
        # If they were born within X years before current year then
 | 
			
		||||
        # assume they are alive (we already know they are not dead).
 | 
			
		||||
@@ -631,7 +633,6 @@ class ProbablyAlive(object):
 | 
			
		||||
                ev = self.db.get_event_from_handle(ev_ref.ref)
 | 
			
		||||
                if ev and ev.type.is_birth_fallback():
 | 
			
		||||
                    birth_date = ev.get_date_object()
 | 
			
		||||
                    explain = _("birth-related evidence")
 | 
			
		||||
 | 
			
		||||
        if not birth_date and death_date:
 | 
			
		||||
            # person died more than MAX after current year
 | 
			
		||||
@@ -983,8 +984,8 @@ def probably_alive(person, db,
 | 
			
		||||
        birth, death, explain))
 | 
			
		||||
    if not birth or not death:
 | 
			
		||||
        # no evidence, must consider alive
 | 
			
		||||
        return (True, None, None, _("no evidence"), None) if return_range \
 | 
			
		||||
                else True
 | 
			
		||||
        return ((True, None, None, _("no evidence"), None) if return_range
 | 
			
		||||
                else True)
 | 
			
		||||
    # must have dates from here:
 | 
			
		||||
    if limit:
 | 
			
		||||
        death += limit # add these years to death
 | 
			
		||||
 
 | 
			
		||||
@@ -1322,6 +1322,36 @@ class Date(object):
 | 
			
		||||
        if day != 0 or dv[Date._POS_DAY] > 28:
 | 
			
		||||
            self.set_yr_mon_day(*self.offset(day))
 | 
			
		||||
 | 
			
		||||
    def set2_yr_mon_day_offset(self, year=0, month=0, day=0):
 | 
			
		||||
        """
 | 
			
		||||
        Set the year, month, and day values by offset.
 | 
			
		||||
        """
 | 
			
		||||
        dv = list(self.dateval)
 | 
			
		||||
        if dv[Date._POS_RYR]:
 | 
			
		||||
            dv[Date._POS_RYR] += year
 | 
			
		||||
        elif year:
 | 
			
		||||
            dv[Date._POS_RYR] = year
 | 
			
		||||
        if dv[Date._POS_RMON]:
 | 
			
		||||
            dv[Date._POS_RMON] += month
 | 
			
		||||
        elif month:
 | 
			
		||||
            if month < 0:
 | 
			
		||||
                dv[Date._POS_RMON] = 1 + month
 | 
			
		||||
            else:
 | 
			
		||||
                dv[Date._POS_RMON] = month
 | 
			
		||||
        # Fix if month out of bounds:
 | 
			
		||||
        if month != 0: # only check if changed
 | 
			
		||||
            if dv[Date._POS_RMON] == 0: # subtraction
 | 
			
		||||
                dv[Date._POS_RMON] = 12
 | 
			
		||||
                dv[Date._POS_RYR] -= 1
 | 
			
		||||
            elif dv[Date._POS_RMON] < 0: # subtraction
 | 
			
		||||
                dv[Date._POS_RYR] -= int((-dv[Date._POS_RMON]) / 12) + 1
 | 
			
		||||
                dv[Date._POS_RMON] = (dv[Date._POS_RMON] % 12)
 | 
			
		||||
            elif dv[Date._POS_RMON] > 12 or dv[Date._POS_RMON] < 1:
 | 
			
		||||
                dv[Date._POS_RYR] += int(dv[Date._POS_RMON] / 12)
 | 
			
		||||
                dv[Date._POS_RMON] = dv[Date._POS_RMON] % 12
 | 
			
		||||
        if day != 0 or dv[Date._POS_RDAY] > 28:
 | 
			
		||||
            self.set2_yr_mon_day(*self.offset(day))
 | 
			
		||||
 | 
			
		||||
    def copy_offset_ymd(self, year=0, month=0, day=0):
 | 
			
		||||
        """
 | 
			
		||||
        Return a Date copy based on year, month, and day offset.
 | 
			
		||||
@@ -1333,6 +1363,9 @@ class Date(object):
 | 
			
		||||
            new_date = self
 | 
			
		||||
        retval = Date(new_date)
 | 
			
		||||
        retval.set_yr_mon_day_offset(year, month, day)
 | 
			
		||||
        if (self.get_modifier() == Date.MOD_RANGE or 
 | 
			
		||||
            self.get_modifier() == Date.MOD_SPAN): 
 | 
			
		||||
            retval.set2_yr_mon_day_offset(year, month, day)
 | 
			
		||||
        if orig_cal == 0:
 | 
			
		||||
            return retval
 | 
			
		||||
        else:
 | 
			
		||||
@@ -1345,6 +1378,9 @@ class Date(object):
 | 
			
		||||
        """
 | 
			
		||||
        retval = Date(self)
 | 
			
		||||
        retval.set_yr_mon_day(year, month, day)
 | 
			
		||||
        if (self.get_modifier() == Date.MOD_RANGE or 
 | 
			
		||||
            self.get_modifier() == Date.MOD_SPAN): 
 | 
			
		||||
            retval.set2_yr_mon_day_offset(year, month, day)
 | 
			
		||||
        return retval
 | 
			
		||||
 | 
			
		||||
    def set_year(self, year):
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user