Linux cal 命令在 9999 年之前是否正确?

Is the Linux cal command correct until year 9999?

cal 命令显然是这样检查闰年的:

if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) then leapyear=true

我的问题是从现在到 9999 年(此命令的有效年份范围)是否还有未包含在该定义中的其他闰年。如果是,这些是否也包含在 cal 命令中?

如果您的文明遵循公历(否则您可能不会使用 Linux),这就是闰年的确切定义。使用这个有点奇怪的定义是因为一个天年(地球绕太阳转一圈)需要 365 多一点,但少于 366 天。它的计算方式是 365 + 1/4 - 1/100 + 1/400 = 365.24925 天。

不符合公历规则,因此 cal 是该日历的正确实现。

公历是否会一直使用到 9999 年,谁也说不准。我的猜测是它不会保持不变,因为它的不精确性在几千年后成为一个值得注意的因素。

热带(自然)年目前大约有 365.2422* 天(随着地球自转减慢,它会随着时间的推移而变多,但速度很慢)。公历的 4-but-not-100-except-400 意味着公历年平均有 365.2425 天。这是一个不错的近似值,但它意味着在地球历史上的这一点上,大约每 3236+ 年就会失去一天。

当人们确定这是一个问题并插入另一个闰日(或完全更改规则)时,cal 的实施者可能无法预测,因此他们坚持规则公历。

*平均。由于来自其他行星的引力,它略有不同。

+ 我查了一下。当然,这个数字也有一些差异。

来自 https://www.timeanddate.com/date/leapyear.html :

In the Gregorian calendar 3 criteria must be taken into account to identify leap years:

  • The year is evenly divisible by 4;
  • If the year can be evenly divided by 100, it is NOT a leap year, unless;
  • The year is also evenly divisible by 400. Then it is a leap year. This means that 2000 and 2400 are leap years, while 1800, 1900, 2100, 2200, 2300 and 2500 are NOT leap years.

查看 cal 的 Debian 源代码: http://anonscm.debian.org/cgit/bsdmainutils/bsdmainutils.git/tree/usr.bin/ncal/calendar.c#n205

看起来他们确实在做正确的事。