Fixed error in leap year calculation for Julian calendar, issue #2639.
svn: r11700
This commit is contained in:
parent
b391b2b985
commit
11da237db7
@ -75,6 +75,23 @@ def gregorian_valid(date_tuple):
|
||||
valid = False
|
||||
return valid
|
||||
|
||||
def julian_valid(date_tuple):
|
||||
day = date_tuple[0]
|
||||
month = date_tuple[1]
|
||||
valid = True
|
||||
try:
|
||||
if month > 12:
|
||||
valid = False
|
||||
elif (date_tuple[2]) % 4 == 0:
|
||||
# julian always have leapyear every 4 year
|
||||
if day > _leap_days[month-1]:
|
||||
valid = False
|
||||
elif day > _max_days[month-1]:
|
||||
valid = False
|
||||
except:
|
||||
valid = False
|
||||
return valid
|
||||
|
||||
def swedish_valid(date_tuple):
|
||||
valid = gregorian_valid(date_tuple)
|
||||
# not sure how <= and >= works with tuples???
|
||||
@ -226,8 +243,8 @@ class DateParser:
|
||||
def __init__(self):
|
||||
self.init_strings()
|
||||
self.parser = {
|
||||
Date.CAL_GREGORIAN : self._parse_greg_julian,
|
||||
Date.CAL_JULIAN : self._parse_greg_julian,
|
||||
Date.CAL_GREGORIAN : self._parse_gregorian,
|
||||
Date.CAL_JULIAN : self._parse_julian,
|
||||
Date.CAL_FRENCH : self._parse_french,
|
||||
Date.CAL_PERSIAN : self._parse_persian,
|
||||
Date.CAL_HEBREW : self._parse_hebrew,
|
||||
@ -363,9 +380,14 @@ class DateParser:
|
||||
return self._parse_calendar(text, self._ftext, self._ftext2,
|
||||
self.french_to_int, french_valid)
|
||||
|
||||
def _parse_greg_julian(self, text):
|
||||
def _parse_gregorian(self, text):
|
||||
return self._parse_calendar(text, self._text, self._text2,
|
||||
self.month_to_int, gregorian_valid)
|
||||
|
||||
def _parse_julian(self, text):
|
||||
return self._parse_calendar(text, self._text, self._text2,
|
||||
self.month_to_int, julian_valid)
|
||||
|
||||
def _parse_swedish(self, text):
|
||||
return self._parse_calendar(text, self._stext, self._stext2,
|
||||
self.swedish_to_int,swedish_valid)
|
||||
@ -429,16 +451,22 @@ class DateParser:
|
||||
Convert only the date portion of a date.
|
||||
"""
|
||||
if subparser is None:
|
||||
subparser = self._parse_greg_julian
|
||||
subparser = self._parse_gregorian
|
||||
|
||||
if subparser == self._parse_greg_julian:
|
||||
if subparser == self._parse_gregorian:
|
||||
check = gregorian_valid
|
||||
|
||||
elif subparser == self._parse_julian:
|
||||
check = julian_valid
|
||||
|
||||
elif subparser == self._parse_swedish:
|
||||
check = swedish_valid
|
||||
|
||||
elif subparser == self._parse_french:
|
||||
check = french_valid
|
||||
else:
|
||||
check = None
|
||||
|
||||
value = subparser(text)
|
||||
if value != Date.EMPTY:
|
||||
return value
|
||||
|
Loading…
Reference in New Issue
Block a user