Subject: | Gets the date wrong under obscure conditions |
In the course of an argument over whether Easter can occur on March 22, I ran a large block of dates (1583-2500) through Date::Easter using ActiveState perl, v5.8.3 built for MSWin32-x86-multi-thread on Windows XP Home. Someone pointed out to me that Easter Day 2133 is on April 19, not March 22. I verified that 4/19 is correct, using the information at http://www.tondering.dk/claus/cal/node3.html#SECTION003120000000000000000
In looking at the source on CPAN, the formulas used by the module are different from the code I came up with to reproduce the calculations from the web site. My code is below.
For an easier-to-verify example, Easter in 1893 was on April 2 (verified here: http://www.smart.net/~mmontes/freq3.html#LBY), but the module returns April 9.
Code:
#!/usr/bin/perl
use strict;
use Date::Easter;
my ($g, $c, $h, $i, $j, $l, $month, $day, $year, $m2, $d2);
for ($year = 1582; $year < 2500; $year++) {
$g = $year % 19;
$c = int($year / 100);
$h = ($c - int($c / 4) - int((8 * $c + 13) / 25) + 19 * $g - 15) % 30;
$i = $h - int ($h / 28) * (1 - int(29 / ($h + 1)) * int ((21 - $g) / 11));
$j = ($year + int($year / 4) + $i + 2 - $c + int($c / 4)) % 7;
$l = $i - $j;
$month = 3 + int(($l + 40) / 44);
$day = $l + 28 - 31 * int($month / 4);
($m2, $d2) = easter($year);
if (($m2 != $month) || ($d2 != $day)) {
print "Didn't match in $year: mine $month $day, module $m2, $d2\n";
}
}