Published in: PHP
URL: http://reusablecode.blogspot.com/2008/03/calculating-easter.html
Function library for calculation of Easter and related ecclesiastical holidays.
<?php /* PHP Easter Calculation Library Copyright (c) 2008, reusablecode.blogspot.com; some rights reserved. This work is licensed under the Creative Commons Attribution License. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. This function library allows calculation of the following ecclesiastical holidays: Ash Wednesday, Palm Sunday, Good Friday, Easter, Ascension Day, and Pentecost. Refer to Wikipedia for information on the purpose of these holidays.. */ // Determine the date of Easter for a given year. function dateEaster($someYear) { if ($someYear <= 1752) { // Julian calendar } else { // Gregorian calendar $solarCorrection = ($someYear - 1600) / 100 - ($someYear - 1600) / 400; $lunarCorrection = ((($someYear - 1400) / 100) * 8) / 25; } while ($dominicalNumber < 0) { $dominicalNumber += 7; } while ($paschalFullMoon < 0) { $paschalFullMoon += 30; } if ($paschalFullMoon == 29 || ($paschalFullMoon == 28 && $goldenNumber > 11)) { $paschalFullMoon--; } if ($difference < 0) { $difference += 7; } $dayEaster = $paschalFullMoon + $difference + 1; if ($dayEaster < 11) { // Easter occurs in March. } else { // Easter occurs in April. } return $dateEaster; } // Determine the date of Good Friday for a given year. // Requires dateEaster() function dateGoodFriday($someYear) { } // Determine the date of Palm Sunday for a given year. // Requires dateEaster() function datePalmSunday($someYear) { } // Determines the date of Ash Wednesday for a given year. // Requires dateEaster() function dateAshWednesday($someYear) { } // Deteremines the date of Ascension Day for a given year. // Requires dateEaster() function dateAscensionDay($someYear) { } // Determines the date of Pentecost for a given year. // Requires dateEaster() function datePentecost($someYear) { } // Unit tests // $testYear = 2008; // echo "Ash Wednesday: " . date("j F Y", dateAshWednesday($testYear)) . "<br>"; // echo "Palm Sunday: " . date("j F Y", datePalmSunday($testYear)) . "<br>"; // echo "Good Friday: " . date("j F Y", dateGoodFriday($testYear)) . "<br>"; // echo "Easter: " . date("j F Y", dateEaster($testYear)) . "<br>"; // echo "Ascension Day: " . date("j F Y", dateAscensionDay($testYear)) . "<br>"; // echo "Pentecost: " . date("j F Y", datePentecost($testYear)) . "<br>"; ?>
You need to login to post a comment.
