It's Easter weekend, and as promised we're going to write a function to calculate when Easter occurs for a given year. Easter is a strange holiday in that it jumps around the calendar between March and April. This is because it is tied to the lunar cycle. Easter occurs on the first Sunday after the Paschal full moon.
ASP
function dateEaster(someYear)
Dim goldenNumber
Dim solarCorrection
Dim lunarCorrection
Dim paschalFullMoon
Dim dominicalNumber
Dim difference
Dim dayEaster
goldenNumber = (someYear Mod 19) + 1
if someYear <= 1752 then
' Julian calendar
dominicalNumber = (someYear + (someYear / 4) + 5) Mod 7
paschalFullMoon = (3 - (11 * goldenNumber) - 7) Mod 30
else
' Gregorian calendar
dominicalNumber = (someYear + (someYear / 4) - (someYear / 100) + (someYear / 400)) Mod 7
solarCorrection = (someYear - 1600) / 100 - (someYear - 1600) / 400
lunarCorrection = (((someYear - 1400) / 100) * 8) / 25
paschalFullMoon = (3 - 11 * goldenNumber + solarCorrection - lunarCorrection) Mod 30
end if
do until dominicalNumber > 0
dominicalNumber = dominicalNumber + 7
loop
do until paschalFullMoon > 0
paschalFullMoon = paschalFullMoon + 30
loop
if paschalFullMoon = 29 or (paschalFullMoon = 28 and goldenNumber > 11) then
paschalFullMoon = paschalFullMoon - 1
end if
difference = (4 - paschalFullMoon - dominicalNumber) Mod 7
if difference < 0 then
difference = difference + 7
end if
dayEaster = paschalFullMoon + difference + 1
if dayEaster < 11 then
' Easter occurs in March.
dateEaster = DateSerial(someYear, 3, dayEaster + 21)
else
' Easter occurs in April.
dateEaster = DateSerial(someYear, 4, dayEaster - 10)
end if
end function
PHP
function dateEaster($someYear)
{
$goldenNumber = fmod($someYear, 19) + 1;
if ($someYear <= 1752)
{
// Julian calendar
$dominicalNumber = fmod($someYear + ($someYear / 4) + 5, 7);
$paschalFullMoon = fmod(3 - (11 * $goldenNumber) - 7, 30);
}
else
{
// Gregorian calendar
$dominicalNumber = fmod($someYear + ($someYear / 4) - ($someYear / 100) + ($someYear / 400), 7);
$solarCorrection = ($someYear - 1600) / 100 - ($someYear - 1600) / 400;
$lunarCorrection = ((($someYear - 1400) / 100) * 8) / 25;
$paschalFullMoon = fmod(3 - 11 * $goldenNumber + $solarCorrection - $lunarCorrection, 30);
}
while ($dominicalNumber < 0)
{
$dominicalNumber += 7;
}
while ($paschalFullMoon < 0)
{
$paschalFullMoon += 30;
}
if ($paschalFullMoon == 29 || ($paschalFullMoon == 28 && $goldenNumber > 11))
{
$paschalFullMoon--;
}
$difference = fmod(4 - $paschalFullMoon - $dominicalNumber, 7);
if ($difference < 0)
{
$difference += 7;
}
$dayEaster = $paschalFullMoon + $difference + 1;
if ($dayEaster < 11)
{
// Easter occurs in March.
$dateEaster = mktime(0, 0, 0, 3, $dayEaster + 21, $someYear);
}
else
{
// Easter occurs in April.
$dateEaster = mktime(0, 0, 0, 4, $dayEaster - 10, $someYear);
}
return $dateEaster;
}
We can calculate the other ecclesiastical holidays by offsetting the date of Easter with the number of days between Easter and the holiday we're looking for.
ASP
function dateGoodFriday(someYear)
dateGoodFriday = DateAdd("d", -2, dateEaster(someYear))
end function
function datePalmSunday(someYear)
datePalmSunday = DateAdd("d", -7, dateEaster(someYear))
end function
function dateAshWednesday(someYear)
dateAshWednesday = DateAdd("d", -46, dateEaster(someYear))
end function
function dateAscensionDay(someYear)
dateAscensionDay = DateAdd("d", 39, dateEaster(someYear))
end function
function datePentecost(someYear)
datePentecost = DateAdd("d", 49, dateEaster(someYear))
end function
PHP
function dateGoodFriday($someYear)
{
$easter = getDate(dateEaster($someYear));
return mktime(0, 0, 0, $easter[mon], $easter[mday] - 2, $easter[year]);
}
function datePalmSunday($someYear)
{
$easter = getDate(dateEaster($someYear));
return mktime(0, 0, 0, $easter[mon], $easter[mday] - 7, $easter[year]);
}
function dateAshWednesday($someYear)
{
$easter = getDate(dateEaster($someYear));
return mktime(0, 0, 0, $easter[mon], $easter[mday] - 46, $easter[year]);
}
function dateAscensionDay($someYear)
{
$easter = getDate(dateEaster($someYear));
return mktime(0, 0, 0, $easter[mon], $easter[mday] + 39, $easter[year]);
}
function datePentecost($someYear)
{
$easter = getDate(dateEaster($someYear));
return mktime(0, 0, 0, $easter[mon], $easter[mday] + 49, $easter[year]);
}
No comments:
Post a Comment