From 5d276ee14620db5e3901f2d1172a1af2f3287db5 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Wed, 17 Oct 2007 04:07:26 +0000 Subject: [PATCH] 2007-10-17 Douglas S. Blank * src/gen/lib/date.py: added method Date.offset(value) -> (y,m,d) svn: r9200 --- ChangeLog | 3 +++ src/gen/lib/date.py | 29 +++++++++++++++-------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index d58415257..44ceeda4a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2007-10-17 Douglas S. Blank + * src/gen/lib/date.py: added method Date.offset(value) -> (y,m,d) + 2007-10-16 Don Allingham * src/DataViews/_PersonView.py (PersonView.delete_person_response): use gen.utils.delete_person_from_database diff --git a/src/gen/lib/date.py b/src/gen/lib/date.py index dae157a3c..29c323ced 100644 --- a/src/gen/lib/date.py +++ b/src/gen/lib/date.py @@ -265,8 +265,7 @@ class Date: """ new_date = Date() new_date.set_yr_mon_day(dateval[0], dateval[1], dateval[2]) - return Date._calendar_change[Date.CAL_GREGORIAN]( - new_date.sortval + offset) + return new_date.offset(offset) datecopy = Date(self) #we do all calculation in Gregorian calendar @@ -333,17 +332,13 @@ class Date: other_start, other_stop = other_date.get_start_stop_range() self_start, self_stop = self.get_start_stop_range() - ##DEBUG print " date compare:", self_start, self_stop, other_start, - ##DEBUG other_stop + #DEBUG print "compare:",self_start,self_stop,other_start,other_stop # If some overlap then match is True, otherwise False. - if ((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)): - return True - else: - return 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)) def __str__(self): """ @@ -759,13 +754,19 @@ class Date: and self.get_year_valid() and self.get_month_valid() \ and self.get_day_valid() + def offset(self, value): + """ + Returns (year, month, day) of this date +- value. + """ + return Date._calendar_change[Date.CAL_GREGORIAN](self.sortval + value) + + # if __name__ == "__main__": # # Test function. Call it as follows from the command line (so as to find # # imported modules): -# # export PYTHONPATH=/path/to/gramps/src python src/gen.lib/_Date.py +# # export PYTHONPATH=/path/to/gramps/src python src/gen/lib/date.py # # -# from DateHandler import _DateParser -# df = _DateParser.DateParser() # date factory +# from DateHandler import parser as df # def test_date(d1, d2, expected1, expected2 = None): # if expected2 == None: # expected2 = expected1