7068: undo french fallback to gregorian

French SDN conversion functions now accept an optional boolean
parameter that allows to block dates outside the republican period.
By default, calendar conversions are allowed.
Revert test blocked by r23139, it now passes!

svn: r23167
This commit is contained in:
Vassilii Khachaturov 2013-09-19 22:54:49 +00:00
parent 180cb1ac28
commit 407b059dba
2 changed files with 17 additions and 24 deletions

View File

@ -463,29 +463,28 @@ def gregorian_ymd(sdn):
year = year - 1 year = year - 1
return (year, month, day) return (year, month, day)
def french_sdn(year, month, day): def _check_republican_period(sdn, restrict_period):
# French Republican calendar wasn't in use before 22.9.1792 or after 1.1.1806
if restrict_period and (sdn < 2375840 or sdn > 2380688):
raise ValueError("Outside of the French Republican period")
def french_sdn(year, month, day, restrict_period=False):
"""Convert a French Republican Calendar date to an SDN number.""" """Convert a French Republican Calendar date to an SDN number."""
sdn = (year*_FR_DAYS_PER_4_YEARS) // 4 + \ sdn = (year*_FR_DAYS_PER_4_YEARS) // 4 + \
(month-1)*_FR_DAYS_PER_MONTH + \ (month-1)*_FR_DAYS_PER_MONTH + \
day + _FR_SDN_OFFSET day + _FR_SDN_OFFSET
# do not convert dates before 22.9.1792 or after 1.1.1806 _check_republican_period(sdn, restrict_period)
if sdn < 2375840 or sdn > 2380688 : return sdn
return gregorian_sdn(year, month, day)
else:
return sdn
def french_ymd(sdn): def french_ymd(sdn, restrict_period=False):
"""Convert an SDN number to a French Republican Calendar date.""" """Convert an SDN number to a French Republican Calendar date."""
# only between 22.9.1792 and 1.1.1806 _check_republican_period(sdn, restrict_period)
if sdn >= 2375840 and sdn <= 2380688: temp = (sdn-_FR_SDN_OFFSET)*4 - 1
temp = (sdn-_FR_SDN_OFFSET)*4 - 1 year = temp // _FR_DAYS_PER_4_YEARS
year = temp // _FR_DAYS_PER_4_YEARS day_of_year = (temp % _FR_DAYS_PER_4_YEARS) // 4
day_of_year = (temp % _FR_DAYS_PER_4_YEARS) // 4 month = (day_of_year // _FR_DAYS_PER_MONTH) + 1
month = (day_of_year // _FR_DAYS_PER_MONTH) + 1 day = (day_of_year % _FR_DAYS_PER_MONTH) + 1
day = (day_of_year % _FR_DAYS_PER_MONTH) + 1 return (year, month, day)
return (year, month, day)
else:
return gregorian_ymd(sdn)
def persian_sdn(year, month, day): def persian_sdn(year, month, day):
"""Convert a Persian date to an SDN number.""" """Convert a Persian date to an SDN number."""

View File

@ -193,13 +193,7 @@ for calendar in (Date.CAL_JULIAN,
d.set(quality,modifier,calendar,(4,month,1789,False),"Text comment") d.set(quality,modifier,calendar,(4,month,1789,False),"Text comment")
dates.append( d) dates.append( d)
@unittest.skip('Blocked by bug# 7068') for calendar in (Date.CAL_HEBREW, Date.CAL_FRENCH):
# please restore the commented "for" line below upon fixing the bug!!
# then remove this class and the skip above it...
class TestFrenchCalBeforeFrenchRevolution(unittest.TestCase):
pass
#for calendar in (Date.CAL_HEBREW, Date.CAL_FRENCH):
for calendar in [Date.CAL_HEBREW]:
for month in range(1,14): for month in range(1,14):
d = Date() d = Date()
d.set(quality,modifier,calendar,(4,month,1789,False),"Text comment") d.set(quality,modifier,calendar,(4,month,1789,False),"Text comment")