© 2008 Michael Thompson
php Algorithm for
[ Main Index ]
|
| Holiday | |
|---|---|
| Mardi Gras | Tue, Feb 5th |
| Ash Wednesday | Wed, Feb 6th |
| Palm Sunday | Sun, Mar 16th |
| Maundy Thursday | Thu, Mar 20th |
| Good Friday | Fri, Mar 21st |
| Easter | Sun, Mar 23rd |
| Quasimodo Sunday | Sun, Mar 30th |
| Rogation Sunday | Sun, Apr 27th |
| Ascension Thursday | Thu, May 1st |
| Pentecost | Sun, May 11th |
| Trinity Sunday | Sun, May 18th |
| Corpus Christi | Thu, May 22nd |
To determine the date of the Easter holidays for a given year:
The date of Easter Day was defined by the Council of Nicaea in AD325 as the Sunday after the first full moon which falls on or after the Spring Equinox. The Equinox is assumed to always fall on 21st March, so the calculation reduces to determining the date of the full moon and the date of the following Sunday. The algorithm used here was introduced around the year 532 by Dionysius Exiguus. Under the Julian Calendar a simple 19-year cycle is used to track the phases of the Moon. Under the Gregorian Calendar (devised by Clavius and Lilius, and introduced by Pope Gregory XIII in October 1582, and into Britain and its then colonies in September 1752) two correction factors are added to make the cycle more accurate.
function tmEaster($year,$EasterDay=0)
{
################################################################
# if you have php v3.1 or greater use the following to get the
# value for Easter
#
# $rtn = mktime(0,0,0,3,21 + easter_days($year),$year);
#
# otherwise we need to do it the long way...
################################################################
$golden = ($year % 19) + 1;
if( $year <= 1752 )
{
# Julian calendar
$dom = floor(($year + ($year/4) + 5) % 7);
if( $dom<0 ) $dom += 7;
$pfm = floor((3 - (11 * $golden) - 7) % 30);
}
else
{
# Gregorian calendar
$dom = ($year + ($year/4) - ($year/100) + ($year/400)) % 7;
if( $dom<0 ) $dom += 7;
$solar = floor(($year - 1600)/100 - ($year - 1600)/400);
$lunar = floor(((($year - 1400)/100) * 8) /25);
$pfm = floor((3 - (11 * $golden) + $solar - $lunar) % 30);
}
if( $pfm<0 ) $pfm += 30;
if( ($pfm==29) || ($pfm==28 && $golden>11) ) $pfm--;
$tmp = floor((4 - $pfm - $dom) % 7);
if( $tmp<0 ) $tmp += 7;
$easter = $pfm + $tmp + (date("L",mktime(0,0,0,1,1,$year))!=0?0:1);
if( $easter<11 )
{
$mo = 3;
$da = $easter + 21;
}
else
{
$mo = 4;
$da = $easter - 10;
}
$rtn = mktime(0,0,0,$mo,$da,$year);
################################################################
if( $EasterDay!=0 )
{
$mo = date("n",$rtn);
$da = date("j",$rtn);
switch( $EasterDay )
{
case 1: # Palm Sunday
$rtn = mktime(0,0,0,$mo,$da - 7,$year);
break;
case 2: # $Mardi Gras
$rtn = mktime(0,0,0,$mo,$da - 47,$year);
break;
case 3: # Ash Wednesday
$rtn = mktime(0,0,0,$mo,$da - 46,$year);
break;
case 4: # Holy Thursday
$rtn = mktime(0,0,0,$mo,$da - 3,$year);
break;
case 5: # Good Friday
$rtn = mktime(0,0,0,$mo,$da - 2,$year);
break;
case 6: # Passover
$rtn = mktime(0,0,0,$mo,$da - 6,$year);
break;
case 7: # Pentecost
$rtn = mktime(0,0,0,$mo,$da + 49,$year);
break;
case 8: # Ascension
$rtn = mktime(0,0,0,$mo,$da + (49 - 10),$year);
break;
case 9: # Pentecost
$rtn = mktime(0,0,0,$mo,$da + (49 + 7),$year);
break;
case 10: # Rogation Sunday
$rtn = mktime(0,0,0,$mo,$da + 35,$year);
break;
case 11: # Corpus Christi
$rtn = mktime(0,0,0,$mo,$da + (49 + 11),$year);
break;
case 13: # Quasimodo Sunday
$rtn = mktime(0,0,0,$mo,$da + 7,$year);
break;
}
}
return $rtn;
}