General polish of some date handling code; fixed a bug in date comparisons involving 'ABT' dates
svn: r10592
This commit is contained in:
		| @@ -232,6 +232,10 @@ class SimpleTable: | ||||
|                 self.row_sort_val(col, item.sortval) | ||||
|                 if (self.__link_col == col or link == None): | ||||
|                     link = ('Date', item) | ||||
|             elif isinstance(item, gen.lib.Span): | ||||
|                 text = str(item) | ||||
|                 retval.append(text) | ||||
|                 self.row_sort_val(col, float(item)) | ||||
|             else: | ||||
|                 raise AttributeError, ("unknown object type: '%s': %s" %  | ||||
|                                        (item, type(item))) | ||||
|   | ||||
							
								
								
									
										15
									
								
								src/Utils.py
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								src/Utils.py
									
									
									
									
									
								
							| @@ -578,7 +578,7 @@ def probably_alive(person, db, current_date=None, limit=0): | ||||
|                    (defaults to today) | ||||
|     limit        - number of years to check beyond death_date | ||||
|     """ | ||||
|     if not current_date: | ||||
|     if current_date == None: | ||||
|         current_date = gen.lib.Date() | ||||
|         # yr, mon, day: | ||||
|         current_date.set_yr_mon_day(*time.localtime(time.time())[0:3]) | ||||
| @@ -617,15 +617,18 @@ def probably_alive(person, db, current_date=None, limit=0): | ||||
|     birth_ref = person.get_birth_ref() | ||||
|     if birth_ref and birth_ref.get_role() == gen.lib.EventRoleType.PRIMARY: | ||||
|         birth = db.get_event_from_handle(birth_ref.ref) | ||||
|         if birth.get_date_object().get_start_date() != gen.lib.Date.EMPTY: | ||||
|         if (birth.get_date_object().get_start_date() != gen.lib.Date.EMPTY): | ||||
|             if not birth_date: | ||||
|                 birth_date = birth.get_date_object() | ||||
|             # Check whether the birth event is too old because the | ||||
|             # code above did not look at birth, only at other events | ||||
|             if too_old(birth.get_date_object(), current_date.get_year()): | ||||
|                 return False | ||||
|             if not_too_old(birth.get_date_object(), current_date.get_year()): | ||||
|                 return True | ||||
|             birth_obj = birth.get_date_object() | ||||
|             if birth_obj.get_valid(): | ||||
|                 # only if this is a valid birth: | ||||
|                 if too_old(birth_obj, current_date.get_year()): | ||||
|                     return False | ||||
|                 if not_too_old(birth_obj, current_date.get_year()): | ||||
|                     return True | ||||
|      | ||||
|     if not birth_date and death_date: | ||||
|         if death_date.match(current_date.copy_offset_ymd(year=_MAX_AGE_PROB_ALIVE), ">>"): | ||||
|   | ||||
| @@ -23,7 +23,7 @@ | ||||
| """The core library of GRAMPS objects""" | ||||
|  | ||||
| # Dates | ||||
| from gen.lib.date import Date, DateError | ||||
| from gen.lib.date import Date, DateError, Span | ||||
|  | ||||
| # Secondary objects | ||||
| from gen.lib.secondaryobj import SecondaryObject | ||||
|   | ||||
| @@ -86,9 +86,19 @@ class Span: | ||||
|         return retval | ||||
|  | ||||
|     def __int__(self): | ||||
|         return int(self.diff_tuple[0] * 12 + self.diff_tuple[1]) # months | ||||
|         return int(self.diff_tuple[0] * 12 +  | ||||
|                    self.diff_tuple[1] | ||||
|                    ) # number of months, for sorting | ||||
|  | ||||
|     def __float__(self): | ||||
|         return float(self.diff_tuple[0] * 12 +  | ||||
|                      self.diff_tuple[1] + | ||||
|                      self.diff_tuple[2]/31.0  | ||||
|                      ) # number of months, for sorting | ||||
|      | ||||
|     def __eq__(self, other): | ||||
|         if other == None: | ||||
|             return False | ||||
|         return self.diff_tuple == other.diff_tuple | ||||
|  | ||||
| #------------------------------------------------------------------------- | ||||
| @@ -353,7 +363,7 @@ class Date: | ||||
|             eDate = date1 - (years, months, days) | ||||
|             if eDate << date2: # too small, strictly less than | ||||
|                 diff = 0 | ||||
|                 while eDate < date2 and diff < 60: | ||||
|                 while eDate << date2 and diff < 60: | ||||
|                     diff += 1 | ||||
|                     eDate = eDate + (0, 0, diff) | ||||
|                 if diff == 60: | ||||
| @@ -361,7 +371,7 @@ class Date: | ||||
|                 return Span(years, months, days - diff) | ||||
|             elif eDate >> date2: | ||||
|                 diff = 0 | ||||
|                 while eDate > date2 and diff > -60: | ||||
|                 while eDate >> date2 and diff > -60: | ||||
|                     diff -= 1 | ||||
|                     eDate = eDate - (0, 0, abs(diff)) | ||||
|                 if diff == -60: | ||||
|   | ||||
| @@ -862,8 +862,8 @@ class PythonGramplet(Gramplet): | ||||
|                 return True | ||||
|             _retval = self.process_command(line) | ||||
|             if _retval != None: | ||||
|                 self.append_text("%s" % str(_retval)) | ||||
|             self.append_text("\n%s " % self.prompt) | ||||
|                 self.append_text("%s\n" % str(_retval)) | ||||
|             self.append_text("%s " % self.prompt) | ||||
|             end = buffer.get_end_iter() | ||||
|             buffer.place_cursor(end) | ||||
|             return True | ||||
|   | ||||
		Reference in New Issue
	
	Block a user