如果Y可以被4整除,则Y年是a年。
不等于100,或者
分别为100和400
以下来源遵循上述规则:
Python(calendar.monthrange(1000,2)的输出是(5,28))
webconversiononline.com
但是,以下消息来源说1000年是a年:
Linux cal(命令cal 2 1000显示29天)
timeanddate.com
格里高利制于1582年引入,上面的规则显然开始适用(在1582年之前,唯一的要求是4除以完美除法)。 但是,测试其他几个年份的值(100、500、600、700、900、1100、1300、1400、1500和1700)表明,只有在1800年之后(包括1800年),Python和Linux cal的结果才会一致。
为什么这些资料来源给出不同的答案?
calendar模块使用多用公历。
从calendar文档:
Most of these functions and classes rely on the datetime module which
uses an idealized calendar, the current Gregorian calendar extended in
both directions. This matches the definition of the"proleptic
Gregorian" calendar in Dershowitz and Reingold’s book"Calendrical
Calculations", where it’s the base calendar for all computations.
从维基百科:
The proleptic Gregorian
calendar
is produced by extending the Gregorian calendar backward to dates
preceding its official introduction in 1582.
朱利安历法在单个日期没有被公历代替。 各国在不同的时间采用了它。
从我(相当古老)的计算机上的Linux cal手册页中:
-s -file ... -country_code
Assume the switch from Julian to Gregorian Calendar at the date
associated with the country_code If not specified, ncal tries to guess
the switch date from the local environment or falls back to September
2, 1752. This was when Great Britain and her colonies switched to the
Gregorian Calendar.
[...]
BUGS
The assignment of Julian–Gregorian switching dates to country codes is
historically naive for many countries.
Python使用这种幼稚的方法来leap年似乎是不幸的,但是情况可能更糟...