7100: back-port from gramps40
didn't back-port datehandler_test.py additions because no datehandler_test.py on gramps34 :-( svn: r23279
This commit is contained in:
parent
f44ab17578
commit
874be122fb
@ -1568,6 +1568,7 @@ class Date(object):
|
|||||||
self.recalc_sort_value()
|
self.recalc_sort_value()
|
||||||
|
|
||||||
ny = self.get_new_year()
|
ny = self.get_new_year()
|
||||||
|
year_delta = 0
|
||||||
if ny: # new year offset?
|
if ny: # new year offset?
|
||||||
if ny == Date.NEWYEAR_MAR1:
|
if ny == Date.NEWYEAR_MAR1:
|
||||||
split = (3, 1)
|
split = (3, 1)
|
||||||
@ -1579,26 +1580,19 @@ class Date(object):
|
|||||||
split = ny
|
split = ny
|
||||||
else:
|
else:
|
||||||
split = (0, 0)
|
split = (0, 0)
|
||||||
if (self.get_month(), self.get_day()) >= split:
|
if (self.get_month(), self.get_day()) >= split and split != (0, 0):
|
||||||
d1 = Date(self.get_year(), 1, 1)
|
year_delta = -1
|
||||||
|
d1 = Date(self.get_year() + year_delta, self.get_month(), self.get_day())
|
||||||
d1.set_calendar(self.calendar)
|
d1.set_calendar(self.calendar)
|
||||||
d1_val = d1.sortval
|
self.sortval = d1.sortval
|
||||||
d2 = Date(self.get_year(), split[0], split[1])
|
|
||||||
d2.set_calendar(self.calendar)
|
if text:
|
||||||
d2_val = d2.sortval
|
self.text = text
|
||||||
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
|
|
||||||
|
|
||||||
if modifier != Date.MOD_TEXTONLY:
|
if modifier != Date.MOD_TEXTONLY:
|
||||||
sanity = Date(self)
|
sanity = Date(self)
|
||||||
sanity.convert_calendar(self.calendar, known_valid = False)
|
sanity.convert_calendar(self.calendar, known_valid = False)
|
||||||
|
|
||||||
# We don't do the roundtrip conversion on self, becaue
|
# We don't do the roundtrip conversion on self, becaue
|
||||||
# it would remove uncertainty on day/month expressed with zeros
|
# 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):
|
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
|
# 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):
|
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))
|
format(original, value))
|
||||||
|
|
||||||
# ignore slash difference
|
# ignore slash difference
|
||||||
|
|
||||||
if text:
|
|
||||||
self.text = text
|
|
||||||
|
|
||||||
def recalc_sort_value(self):
|
def recalc_sort_value(self):
|
||||||
"""
|
"""
|
||||||
|
@ -360,6 +360,9 @@ def suite():
|
|||||||
("1706-12-31 (Julian)", "1707-01-01 (Swedish)", True),
|
("1706-12-31 (Julian)", "1707-01-01 (Swedish)", True),
|
||||||
("1712-02-28 (Julian)", "1712-02-29 (Swedish)", True),
|
("1712-02-28 (Julian)", "1712-02-29 (Swedish)", True),
|
||||||
("1712-02-29 (Julian)", "1712-02-30 (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()
|
suite = unittest.TestSuite()
|
||||||
count = 1
|
count = 1
|
||||||
|
Loading…
Reference in New Issue
Block a user