From 874be122fb18894a1c312b3152ea2d73009c3dac Mon Sep 17 00:00:00 2001 From: Vassilii Khachaturov Date: Tue, 8 Oct 2013 12:53:42 +0000 Subject: [PATCH] 7100: back-port from gramps40 didn't back-port datehandler_test.py additions because no datehandler_test.py on gramps34 :-( svn: r23279 --- src/gen/lib/date.py | 42 ++++++++++++++++++----------------- src/gen/lib/test/date_test.py | 3 +++ 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/gen/lib/date.py b/src/gen/lib/date.py index 1ed8d66c5..a667299cf 100644 --- a/src/gen/lib/date.py +++ b/src/gen/lib/date.py @@ -1568,6 +1568,7 @@ class Date(object): self.recalc_sort_value() ny = self.get_new_year() + year_delta = 0 if ny: # new year offset? if ny == Date.NEWYEAR_MAR1: split = (3, 1) @@ -1579,26 +1580,19 @@ class Date(object): split = ny else: split = (0, 0) - if (self.get_month(), self.get_day()) >= split: - d1 = Date(self.get_year(), 1, 1) + if (self.get_month(), self.get_day()) >= split and split != (0, 0): + year_delta = -1 + d1 = Date(self.get_year() + year_delta, self.get_month(), self.get_day()) d1.set_calendar(self.calendar) - d1_val = d1.sortval - d2 = Date(self.get_year(), split[0], split[1]) - d2.set_calendar(self.calendar) - d2_val = d2.sortval - self.sortval -= (d2_val - d1_val) - else: - d1 = Date(self.get_year(), 12, 31) - d1.set_calendar(self.calendar) - d1_val = d1.sortval - d2 = Date(self.get_year(), split[0], split[1]) - d2.set_calendar(self.calendar) - d2_val = d2.sortval - self.sortval += (d1_val - d2_val) + 1 - + self.sortval = d1.sortval + + if text: + self.text = text + if modifier != Date.MOD_TEXTONLY: sanity = Date(self) sanity.convert_calendar(self.calendar, known_valid = False) + # We don't do the roundtrip conversion on self, becaue # it would remove uncertainty on day/month expressed with zeros @@ -1610,15 +1604,23 @@ class Date(object): for d,m,y,sl in zip(*[iter(zl)]*4): # each of d,m,y,sl is a pair from dateval and value, to compare - for adjusted,original in d,m,y: + for adjusted,original in d,m: if adjusted != original and not(original == 0 and adjusted == 1): - raise DateError("Invalid day/month/year {} passed in value {}". + log.debug("Sanity check failed - self: {}, sanity: {}".format( + self.dateval, sanity.dateval)) + raise DateError("Invalid day/month {} passed in value {}". format(original, value)) + adjusted,original = y + adjusted -= year_delta + if adjusted != original and not(original == 0 and adjusted == 1): + log.debug("Sanity check failed - self: {}, sanity: {}".format( + self.dateval, sanity.dateval)) + raise DateError("Invalid year {} passed in value {}". + format(original, value)) + # ignore slash difference - if text: - self.text = text def recalc_sort_value(self): """ diff --git a/src/gen/lib/test/date_test.py b/src/gen/lib/test/date_test.py index f81d986e2..6e2b0ff85 100644 --- a/src/gen/lib/test/date_test.py +++ b/src/gen/lib/test/date_test.py @@ -360,6 +360,9 @@ def suite(): ("1706-12-31 (Julian)", "1707-01-01 (Swedish)", True), ("1712-02-28 (Julian)", "1712-02-29 (Swedish)", True), ("1712-02-29 (Julian)", "1712-02-30 (Swedish)", True), + # See bug# 7100 + ("1233-12-01", "1234-12-01 (Mar25)", True), + ("1234-01-04", "1234-01-04 (Mar25)", True), ] suite = unittest.TestSuite() count = 1