7068: back-port from trunk

svn: r23281
This commit is contained in:
Vassilii Khachaturov 2013-10-08 13:05:34 +00:00
parent 63d6fe766f
commit 2b1df84121

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."""