parent
6815af9303
commit
28ee7ee1a8
@ -89,6 +89,13 @@ def swedish_valid(date_tuple):
|
||||
valid = False
|
||||
return valid
|
||||
|
||||
def french_valid(date_tuple):
|
||||
valid = True
|
||||
# year 1 starts on 22.9.1792
|
||||
if date_tuple[2] < 1:
|
||||
valid = False
|
||||
return valid
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Parser class
|
||||
@ -354,7 +361,7 @@ class DateParser:
|
||||
|
||||
def _parse_french(self, text):
|
||||
return self._parse_calendar(text, self._ftext, self._ftext2,
|
||||
self.french_to_int)
|
||||
self.french_to_int, french_valid)
|
||||
|
||||
def _parse_greg_julian(self, text):
|
||||
return self._parse_calendar(text, self._text, self._text2,
|
||||
@ -428,6 +435,8 @@ class DateParser:
|
||||
check = gregorian_valid
|
||||
if subparser == self._parse_swedish:
|
||||
check = swedish_valid
|
||||
if subparser == self._parse_french:
|
||||
check = french_valid
|
||||
else:
|
||||
check = None
|
||||
|
||||
|
@ -167,7 +167,7 @@ class DateParserFR(DateParser):
|
||||
# This self._numeric is different from the base
|
||||
# avoid bug gregorian / french calendar conversion (+/-10 days)
|
||||
self._numeric = re.compile("((\d+)[/\. ])?\s*((\d+)[/\.])?\s*(\d+)\s*$")
|
||||
self._span = re.compile(u"(de)\s+(?P<start>.+)\s+(à)\s+(?P<stop>.+)", re.IGNORECASE)
|
||||
self._span = re.compile(u"(de)\s+(?P<start>.+)\s+(à)\s+(?P<stop>.+)", re.IGNORECASE)
|
||||
self._range = re.compile(u"(entre|ent\.|ent)\s+(?P<start>.+)\s+(et)\s+(?P<stop>.+)", re.IGNORECASE)
|
||||
# This self._text are different from the base
|
||||
# by adding ".?" after the first date and removing "\s*$" at the end
|
||||
@ -186,6 +186,9 @@ class DateParserFR(DateParser):
|
||||
#islamic
|
||||
self._itext2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._imon_str,
|
||||
re.IGNORECASE)
|
||||
#swedish
|
||||
self._stext2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._smon_str,
|
||||
re.IGNORECASE)
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -247,7 +250,7 @@ class DateDisplayFR(DateDisplay):
|
||||
else:
|
||||
value = "%s %d, %s" % (self.MONS[date_val[1]], date_val[0], year)
|
||||
elif self.format == 4:
|
||||
# Day Month Year
|
||||
# Day. Month Year
|
||||
if date_val[0] == 0:
|
||||
if date_val[1] == 0:
|
||||
value = year
|
||||
@ -258,7 +261,7 @@ class DateDisplayFR(DateDisplay):
|
||||
# value = "%d %s %s" % (date_val[0], self._months[date_val[1]], year)
|
||||
value = "%d. %s %s" % (date_val[0], self._months[date_val[1]], year)
|
||||
else:
|
||||
# Day MON Year
|
||||
# Day. MON Year
|
||||
if date_val[0] == 0:
|
||||
if date_val[1] == 0:
|
||||
value = year
|
||||
@ -273,23 +276,6 @@ class DateDisplayFR(DateDisplay):
|
||||
else:
|
||||
return value
|
||||
|
||||
def _display_french(self, date_val):
|
||||
year = date_val[2]
|
||||
if date_val[0] == 0:
|
||||
if date_val[1] == 0:
|
||||
return year
|
||||
else:
|
||||
return u"%s %d" % (self.french[date_val[1]], year)
|
||||
# convertion mistake before 22.9.1792
|
||||
elif date_val[2] == 0 and date_val[1] == 13:
|
||||
# from 17.9.1792 to 21.9.1792 : trap for Extra months, we cannot date back
|
||||
return self._bce_str % year
|
||||
# on 1792 before 22.9.1792, no negative years
|
||||
elif date_val[2] < 0:
|
||||
return self._bce_str % year
|
||||
# valid dates on 1792
|
||||
else:
|
||||
return u"%s %s %d" % (date_val[0], self.french[date_val[1]], year)
|
||||
|
||||
def display(self, date):
|
||||
"""
|
||||
|
@ -466,18 +466,27 @@ def gregorian_ymd(sdn):
|
||||
|
||||
def french_sdn(year, month, day):
|
||||
"""Convert a French Republican Calendar date to an SDN number."""
|
||||
return (year*_FR_DAYS_PER_4_YEARS)/4 + \
|
||||
sdn = (year*_FR_DAYS_PER_4_YEARS)/4 + \
|
||||
(month-1)*_FR_DAYS_PER_MONTH + \
|
||||
day + _FR_SDN_OFFSET
|
||||
# do not convert dates before 22.9.1792 or after 1.1.1806
|
||||
if sdn < 2375840 or sdn > 2380688 :
|
||||
return gregorian_sdn(year, month, day)
|
||||
else:
|
||||
return sdn
|
||||
|
||||
def french_ymd(sdn):
|
||||
"""Convert an SDN number to a French Republican Calendar date."""
|
||||
temp = (sdn-_FR_SDN_OFFSET)*4 - 1
|
||||
year = temp/_FR_DAYS_PER_4_YEARS
|
||||
day_of_year = (temp%_FR_DAYS_PER_4_YEARS)/4
|
||||
month = (day_of_year/_FR_DAYS_PER_MONTH)+1
|
||||
day = (day_of_year%_FR_DAYS_PER_MONTH)+1
|
||||
return (year, month, day)
|
||||
# only between 22.9.1792 and 1.1.1806
|
||||
if sdn >= 2375840 and sdn <= 2380688:
|
||||
temp = (sdn-_FR_SDN_OFFSET)*4 - 1
|
||||
year = temp/_FR_DAYS_PER_4_YEARS
|
||||
day_of_year = (temp%_FR_DAYS_PER_4_YEARS)/4
|
||||
month = (day_of_year/_FR_DAYS_PER_MONTH)+1
|
||||
day = (day_of_year%_FR_DAYS_PER_MONTH)+1
|
||||
return (year, month, day)
|
||||
else:
|
||||
return gregorian_ymd(sdn)
|
||||
|
||||
def persian_sdn(year, month, day):
|
||||
"""Convert a Persian date to an SDN number."""
|
||||
|
Loading…
Reference in New Issue
Block a user