diff --git a/ChangeLog b/ChangeLog index 7a76769dc..3b1a39f80 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2007-11-21 Douglas S. Blank + * src/gen/lib/date.py: added comparison operator for match() + * src/Utils.py: uses new match comparison + 2007-11-21 Douglas S. Blank * src/Utils.py: probably_alive now takes date rather than year * src/gen/proxy/living.py: create date from year diff --git a/src/Utils.py b/src/Utils.py index e3ceaa8cb..2caad040c 100644 --- a/src/Utils.py +++ b/src/Utils.py @@ -576,9 +576,6 @@ def probably_alive(person, db, current_date=None, limit=0): current_date = gen.lib.Date() # yr, mon, day: current_date.set_yr_mon_day(*time.localtime(time.time())[0:3]) - if (current_date.get_quality() == gen.lib.Date.QUAL_ESTIMATED or - current_date.get_modifier() != gen.lib.Date.MOD_NONE): - raise AttributeError, "probably_alive cannot take esitmated or modified dates" death_date = None # If the recorded death year is before current year then @@ -588,7 +585,7 @@ def probably_alive(person, db, current_date=None, limit=0): death = db.get_event_from_handle(death_ref.ref) if death.get_date_object().get_start_date() != gen.lib.Date.EMPTY: death_date = death.get_date_object() - if death_date.copy_offset_ymd(year=limit) < current_date: + if death_date.copy_offset_ymd(year=limit).match(current_date, "<<"): return False # Look for Cause Of Death, Burial or Cremation events. @@ -601,8 +598,7 @@ def probably_alive(person, db, current_date=None, limit=0): if not death_date: death_date = ev.get_date_object() if ev.get_date_object().get_start_date() != gen.lib.Date.EMPTY: - if (ev.get_date_object().copy_offset_ymd(year=limit) < - current_date): + if ev.get_date_object().copy_offset_ymd(year=limit).match(current_date,"<<"): return False # For any other event of this person, check whether it happened # too long ago. If so then the person is likely dead now. @@ -626,7 +622,7 @@ def probably_alive(person, db, current_date=None, limit=0): return True if not birth_date and death_date: - if death_date > current_date.copy_offset_ymd(year=_MAX_AGE_PROB_ALIVE): + if death_date.match(current_date.copy_offset_ymd(year=_MAX_AGE_PROB_ALIVE), ">>"): # person died more than MAX after current year return False @@ -650,8 +646,8 @@ def probably_alive(person, db, current_date=None, limit=0): # if sibling birth date too far away, then not alive: year = dobj.get_year() if year != 0: - if not (current_date.copy_offset_ymd(-(_MAX_AGE_PROB_ALIVE + _MAX_SIB_AGE_DIFF)) < - dobj < current_date.copy_offset_ymd(_MAX_SIB_AGE_DIFF)): + if not (current_date.copy_offset_ymd(-(_MAX_AGE_PROB_ALIVE + _MAX_SIB_AGE_DIFF)).match(dobj,"<<") and + dobj.match(current_date.copy_offset_ymd(_MAX_SIB_AGE_DIFF),"<<")): return False child_death_ref = child.get_death_ref() if child_death_ref: @@ -661,8 +657,8 @@ def probably_alive(person, db, current_date=None, limit=0): # if sibling death date too far away, then not alive: year = dobj.get_year() if year != 0: - if not (current_date.copy_offset_ymd(-(_MAX_AGE_PROB_ALIVE + _MAX_SIB_AGE_DIFF)) < - dobj < current_date.copy_offset_ymd(_MAX_AGE_PROB_ALIVE)): + if not (current_date.copy_offset_ymd(-(_MAX_AGE_PROB_ALIVE + _MAX_SIB_AGE_DIFF)).match(dobj,"<<") and + dobj.match(current_date.copy_offset_ymd(_MAX_AGE_PROB_ALIVE),"<<")): return False # Try looking for descendants that were born more than a lifespan diff --git a/src/gen/lib/date.py b/src/gen/lib/date.py index 7f2db6fa3..5a2370554 100644 --- a/src/gen/lib/date.py +++ b/src/gen/lib/date.py @@ -305,40 +305,55 @@ class Date: # return tuples not lists, for comparisons return (tuple(startmin), tuple(stopmax)) - def match(self, other_date): + def match(self, other_date, comparison="="): """ The other comparisons for Date don't actually look for anything other than a straight match, or a simple comparison of the sortval. This method allows a more sophisticated comparison looking for - any overlap between two possible dates, date spans, and qualities. - - Returns True if part of other_date matches part of the date-span - defined by self + any match between two possible dates, date spans, and qualities. + + comparison =,== : + Returns True if any part of other_date matches any part of self + comparison < : + Returns True if any part of other_date < any part of self + comparison << : + Returns True if all parts of other_date < all parts of self + comparison > : + Returns True if any part of other_date > any part of self + comparison >> : + Returns True if all parts of other_date > all parts of self """ if (other_date.modifier == Date.MOD_TEXTONLY or self.modifier == Date.MOD_TEXTONLY): - ###from DateHandler import displayer - # If either date is just text, then we can only compare textual - # representations - # Use text as originally given or display date to format - # in preferences? That is use self.text or displayer ? - # It is unclean to import DateHandler in gen.lib ! - ###self_text = displayer.display(self) - self_text = self.text - ##DEBUG: print ' TEXT COMPARE ONLY ' - return (self_text.upper().find(other_date.text.upper()) != -1) + if comparison in ["=", "=="]: + return (self.text.upper().find(other_date.text.upper()) != -1) + else: + return False # Obtain minimal start and maximal stop in Gregorian calendar other_start, other_stop = other_date.get_start_stop_range() - self_start, self_stop = self.get_start_stop_range() + self_start, self_stop = self.get_start_stop_range() - #DEBUG print "compare:",self_start,self_stop,other_start,other_stop - - # If some overlap then match is True, otherwise False. - return ((self_start <= other_start <= self_stop) or - (self_start <= other_stop <= self_stop) or - (other_start <= self_start <= other_stop) or - (other_start <= self_stop <= other_stop)) + if comparison in ["=", "=="]: + # If some overlap then match is True, otherwise False. + return ((self_start <= other_start <= self_stop) or + (self_start <= other_stop <= self_stop) or + (other_start <= self_start <= other_stop) or + (other_start <= self_stop <= other_stop)) + elif comparison == "<": + # If any < any + return self_start < other_stop + elif comparison == "<<": + # If all < all + return self_stop < other_start + elif comparison == ">": + # If any > any + return self_stop > other_start + elif comparison == ">>": + # If all > all + return self_start > other_stop + else: + raise AttributeError, ("invalid match comparison operator: '%s'" % comparison) def __str__(self): """