From b6f7ab9ed0ceeae5784021d126163211f14246ad Mon Sep 17 00:00:00 2001 From: Vassilii Khachaturov Date: Tue, 10 Sep 2013 17:19:16 +0000 Subject: [PATCH] 7034: add remove_stop_date parameter svn: r23083 --- gramps/gen/lib/date.py | 19 +++++++++++++------ gramps/gen/lib/test/date_test.py | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/gramps/gen/lib/date.py b/gramps/gen/lib/date.py index f3fd3acc8..a2086f978 100644 --- a/gramps/gen/lib/date.py +++ b/gramps/gen/lib/date.py @@ -1280,15 +1280,21 @@ class Date(object): dv[pos_day] = day self.dateval = tuple(dv) - def set_yr_mon_day(self, year, month, day, _update2 = True): + def set_yr_mon_day(self, year, month, day, remove_stop_date = None): """ Set the year, month, and day values. - For a compound date, collapses the range/span to the given date. + + @param remove_stop_date Required parameter for a compound date. + When True, the stop date is changed to the same date as well. + When False, the stop date is not changed. """ + if self.is_compound() and remove_stop_date is None: + raise DateError("Required parameter remove_stop_date not set!") + self.__set_yr_mon_day(year, month, day, Date._POS_YR, Date._POS_MON, Date._POS_DAY) self._calc_sort_value() - if _update2 and self.is_compound(): + if remove_stop_date and self.is_compound(): self.set2_yr_mon_day(year, month, day) def _assert_compound(self): @@ -1338,7 +1344,7 @@ class Date(object): """ if self.__set_yr_mon_day_offset(year, month, day, Date._POS_YR, Date._POS_MON, Date._POS_DAY): - self.set_yr_mon_day(*self.offset(day), _update2 = False) + self.set_yr_mon_day(*self.offset(day), remove_stop_date = False) if self.is_compound(): self.set2_yr_mon_day_offset(year, month, day) @@ -1370,12 +1376,13 @@ class Date(object): retval.convert_calendar(orig_cal) return retval - def copy_ymd(self, year=0, month=0, day=0): + def copy_ymd(self, year=0, month=0, day=0, remove_stop_date=None): """ Return a Date copy with year, month, and day set. + @param remove_stop_date Same as in set_yr_mon_day. """ retval = Date(self) - retval.set_yr_mon_day(year, month, day) + retval.set_yr_mon_day(year, month, day, remove_stop_date) return retval def set_year(self, year): diff --git a/gramps/gen/lib/test/date_test.py b/gramps/gen/lib/test/date_test.py index 8cfe9c1ee..a9e1210fb 100644 --- a/gramps/gen/lib/test/date_test.py +++ b/gramps/gen/lib/test/date_test.py @@ -445,7 +445,7 @@ class Test_set2(BaseDateTest): self.assertEqual(stop, (2013, 2, 2)) def test_set_ymd_overrides_both_dates(self): - self.date.set_yr_mon_day(2013, 2, 2) + self.date.set_yr_mon_day(2013, 2, 2, remove_stop_date = True) start,stop = self.date.get_start_stop_range() self.assertEqual(start, stop) self.assertEqual(stop, (2013, 2, 2))