Bug #2614: Error Entering Slash Date; also applied fix for dates that had spaces in them
svn: r11696
This commit is contained in:
parent
799f7579a9
commit
c333394216
@ -162,12 +162,12 @@ class DateDisplay:
|
||||
val = - val
|
||||
|
||||
if slash:
|
||||
if val % 100 == 99:
|
||||
year = "%d/%d" % (val, (val%1000)+1)
|
||||
elif val % 10 == 9:
|
||||
year = "%d/%d" % (val, (val%100)+1)
|
||||
if (val-1) % 100 == 99:
|
||||
year = "%d/%d" % (val - 1, (val%1000))
|
||||
elif (val-1) % 10 == 9:
|
||||
year = "%d/%d" % (val - 1, (val%100))
|
||||
else:
|
||||
year = "%d/%d" % (val, (val%10)+1)
|
||||
year = "%d/%d" % (val - 1, (val%10))
|
||||
else:
|
||||
year = "%d" % (val)
|
||||
|
||||
|
@ -330,8 +330,12 @@ class DateParser:
|
||||
s = False
|
||||
else:
|
||||
d = self._get_int(groups[1])
|
||||
y = int(groups[3])
|
||||
s = groups[4] != None
|
||||
if groups[4] is not None: # slash year "/80"
|
||||
y = int(groups[3]) + 1 # fullyear + 1
|
||||
s = True
|
||||
else: # regular, non-slash date
|
||||
y = int(groups[3])
|
||||
s = False
|
||||
value = (d, m, y, s)
|
||||
if check and not check((d, m, y)):
|
||||
value = Date.EMPTY
|
||||
@ -351,8 +355,12 @@ class DateParser:
|
||||
y = None
|
||||
s = False
|
||||
else:
|
||||
y = int(groups[3])
|
||||
s = groups[4] != None
|
||||
if groups[4] is not None: # slash year digit
|
||||
y = int(groups[3]) + 1 # fullyear + 1
|
||||
s = True
|
||||
else: # regular year
|
||||
y = int(groups[3])
|
||||
s = False
|
||||
value = (d, m, y, s)
|
||||
if check and not check((d, m, y)):
|
||||
value = Date.EMPTY
|
||||
@ -384,8 +392,8 @@ class DateParser:
|
||||
d = self._get_int(groups[4])
|
||||
if check and not check((d, m, y)):
|
||||
return Date.EMPTY
|
||||
if groups[2]:
|
||||
return (d, m, y, True)
|
||||
if groups[2]: # slash year digit
|
||||
return (d, m, y + 1, True)
|
||||
else:
|
||||
return (d, m, y, False)
|
||||
|
||||
@ -511,7 +519,7 @@ class DateParser:
|
||||
try:
|
||||
text = match.group(1) + match.group(3)
|
||||
except:
|
||||
print "MATCH:", match.groups()
|
||||
print "ERROR MATCH:", match.groups()
|
||||
bc = True
|
||||
return (text, bc)
|
||||
|
||||
@ -564,7 +572,7 @@ class DateParser:
|
||||
"""
|
||||
Parses the text and sets the date according to the parsing.
|
||||
"""
|
||||
|
||||
text = text.strip() # otherwise spaces can make it a bad date
|
||||
date.set_text_value(text)
|
||||
qual = Date.QUAL_NONE
|
||||
cal = Date.CAL_GREGORIAN
|
||||
@ -595,10 +603,6 @@ class DateParser:
|
||||
else:
|
||||
date.set(qual, Date.MOD_NONE, cal, subdate)
|
||||
|
||||
if date.get_slash():
|
||||
date.set_calendar(Date.CAL_JULIAN)
|
||||
date.set_year(date.get_year() + 1) # year++ and forces recalc
|
||||
|
||||
def invert_year(self, subdate):
|
||||
return (subdate[0], subdate[1], -subdate[2], subdate[3])
|
||||
|
||||
|
@ -895,14 +895,28 @@ class Date:
|
||||
year = max(value[Date._POS_YR], 1)
|
||||
month = max(value[Date._POS_MON], 1)
|
||||
day = max(value[Date._POS_DAY], 1)
|
||||
|
||||
if year == 0 and month == 0 and day == 0:
|
||||
self.sortval = 0
|
||||
else:
|
||||
func = Date._calendar_convert[calendar]
|
||||
self.sortval = func(year, month, day)
|
||||
|
||||
if self.get_slash() and self.get_calendar() != Date.CAL_JULIAN:
|
||||
self.set_calendar(Date.CAL_JULIAN)
|
||||
self.recalc_sort_value()
|
||||
|
||||
if 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):
|
||||
"""
|
||||
Calculate the numerical sort value associated with the date.
|
||||
|
Loading…
Reference in New Issue
Block a user