0002045: Julian date: year incremented each time event is modified; removed earlier hack, and fixed properly. Other date parsers or displayers may have to change

svn: r10587
This commit is contained in:
Doug Blank 2008-04-19 03:39:58 +00:00
parent fe35c2ff91
commit 3373062274
3 changed files with 34 additions and 12 deletions

View File

@ -162,12 +162,12 @@ class DateDisplay:
val = - val val = - val
if slash: if slash:
if val % 100 == 99: if (val-1) % 100 == 99:
year = "%d/%d" % (val, (val%1000)+1) year = "%d/%d" % (val - 1, (val%1000))
elif val % 10 == 9: elif (val-1) % 10 == 9:
year = "%d/%d" % (val, (val%100)+1) year = "%d/%d" % (val - 1, (val%100))
else: else:
year = "%d/%d" % (val, (val%10)+1) year = "%d/%d" % (val - 1, (val%10))
else: else:
year = "%d" % (val) year = "%d" % (val)

View File

@ -328,8 +328,12 @@ class DateParser:
s = False s = False
else: else:
d = self._get_int(groups[1]) d = self._get_int(groups[1])
if groups[4] != None: # slash year digit
y = int(groups[3][:-1] + groups[4])
s = True
else: # regular, non-slash date
y = int(groups[3]) y = int(groups[3])
s = groups[4] != None s = False
value = (d, m, y, s) value = (d, m, y, s)
if check and not check((d, m, y)): if check and not check((d, m, y)):
value = Date.EMPTY value = Date.EMPTY
@ -348,9 +352,13 @@ class DateParser:
if groups[2] == None: if groups[2] == None:
y = None y = None
s = False s = False
else:
if groups[4] != None: # slash year digit
y = int(groups[3][:-1] + groups[4])
s = True
else: else:
y = int(groups[3]) y = int(groups[3])
s = groups[4] != None s = False
value = (d, m, y, s) value = (d, m, y, s)
if check and not check((d, m, y)): if check and not check((d, m, y)):
value = Date.EMPTY value = Date.EMPTY
@ -382,8 +390,8 @@ class DateParser:
d = self._get_int(groups[4]) d = self._get_int(groups[4])
if check and not check((d, m, y)): if check and not check((d, m, y)):
return Date.EMPTY return Date.EMPTY
if groups[2]: if groups[2]: # slash year digit
return (d, m, y, True) return (d, m, y + 1, True)
else: else:
return (d, m, y, False) return (d, m, y, False)
@ -595,7 +603,7 @@ class DateParser:
if date.get_slash(): if date.get_slash():
date.set_calendar(Date.CAL_JULIAN) date.set_calendar(Date.CAL_JULIAN)
date.set_year(date.get_year() + 1) # year++ and forces recalc date.recalc_sort_value() # needed after the calendar change
def invert_year(self, subdate): def invert_year(self, subdate):
return (subdate[0], subdate[1], -subdate[2], subdate[3]) return (subdate[0], subdate[1], -subdate[2], subdate[3])

View File

@ -578,6 +578,12 @@ class Date:
if self.modifier == Date.MOD_TEXTONLY: if self.modifier == Date.MOD_TEXTONLY:
val = self.text val = self.text
elif self.get_slash():
val = "%04d/%d-%02d-%02d" % (
self.dateval[Date._POS_YR] - 1,
(self.dateval[Date._POS_YR]) % 10,
self.dateval[Date._POS_MON],
self.dateval[Date._POS_DAY])
elif self.modifier == Date.MOD_RANGE or self.modifier == Date.MOD_SPAN: elif self.modifier == Date.MOD_RANGE or self.modifier == Date.MOD_SPAN:
val = "%04d-%02d-%02d - %04d-%02d-%02d" % ( val = "%04d-%02d-%02d - %04d-%02d-%02d" % (
self.dateval[Date._POS_YR], self.dateval[Date._POS_MON], self.dateval[Date._POS_YR], self.dateval[Date._POS_MON],
@ -962,6 +968,14 @@ class Date:
if text: if text:
self.text = text self.text = text
def recalc_sort_value(self):
"""
Recalculates the numerical sort value associated with the date
and returns it. Public method.
"""
self._calc_sort_value()
return self.sortval
def _calc_sort_value(self): def _calc_sort_value(self):
""" """
Calculate the numerical sort value associated with the date. Calculate the numerical sort value associated with the date.