From f637730a87da55b8092ebd0e2bbf058833adf353 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Sat, 19 Apr 2008 16:48:46 +0000 Subject: [PATCH] General polish of some date handling code; fixed a bug in date comparisons involving 'ABT' dates svn: r10592 --- src/Simple/_SimpleTable.py | 4 ++++ src/Utils.py | 15 +++++++++------ src/gen/lib/__init__.py | 2 +- src/gen/lib/date.py | 16 +++++++++++++--- src/plugins/DefaultGramplets.py | 4 ++-- 5 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/Simple/_SimpleTable.py b/src/Simple/_SimpleTable.py index d5a7c5f9d..26bf250ac 100644 --- a/src/Simple/_SimpleTable.py +++ b/src/Simple/_SimpleTable.py @@ -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))) diff --git a/src/Utils.py b/src/Utils.py index 19229100d..fbe7d4908 100644 --- a/src/Utils.py +++ b/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), ">>"): diff --git a/src/gen/lib/__init__.py b/src/gen/lib/__init__.py index 0dd489f61..f7b486e1b 100644 --- a/src/gen/lib/__init__.py +++ b/src/gen/lib/__init__.py @@ -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 diff --git a/src/gen/lib/date.py b/src/gen/lib/date.py index 6e7f6238d..3c0c2cd31 100644 --- a/src/gen/lib/date.py +++ b/src/gen/lib/date.py @@ -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: diff --git a/src/plugins/DefaultGramplets.py b/src/plugins/DefaultGramplets.py index 0e6a3c486..a4272947f 100644 --- a/src/plugins/DefaultGramplets.py +++ b/src/plugins/DefaultGramplets.py @@ -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