Location: PHPKode > scripts > Anglican Calendar Script > anglican-calendar-script/calendar.php
					<h3>
					<?php
/*
    ANGLICAN CALENDAR SCRIPT
    Version 0.16
    1 January 2009
    
    This program has one purpose: to determine and write out the applicable
    liturgical day under the "traditional" Anglican and Episcopal calendar 
    for the current day (for the server; the viewer might actually be in a
    different day.)
    
    By "traditional" we mean as enumerated in the 1662 (Church of England)
    and 1928 (Protestant Episcopal Church) prayer books.  Both of these prayer
    books can be downloaded from http://www.vulcanhammer.org/anglican/.
    
    The program can return up to three results:
    
    1. The specific Sunday in the church year, which is repeated during the following week
       unless a major event intervenes (such as Christmas, Epiphany, Ash Wednesday, 
       Asension Day, etc.)
    2. The saint's feast or other holy day, such as Holy Innocents, All Saints, etc.  We 
       have restricted these days to those days which have collects, epistles and gospels
       for the Holy Communion.
    3. Whether a day is a Rogation or Ember Day.
    
    We have opted to present these without any rules of precedence, as these vary between the
    two prayer books listed above.
    
    You can include this script either directly into the web page or as an include, which is
    the way it's done at its home site.  This copy of the script displays the result in "h3" format,
    which can be modified by changing the tags at the start and end of the program.
    
    Suggestions and error notices can be sent to me by visting the comment page of my 
    websites http://www.vulcanhammer.org/ or http://www.vulcanhammer.net/.  Additional copies
    of the script may be downloaded by visiting http://www.vulcanhammer.org/anglican/calendar/.  If you
    modify and/or redistribute this code, we ask that attribution to the original code and 
    author be maintained.  Additional terms and conditions are detailed below.
    
    Copyright (C) 2005-2009 Don C. Warrington

    This program is free software; you can redistribute it and/or modify
    it under the terms of version 2 of the GNU General Public License as published by
    the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    
    Version History:
    0.1, 21 January 2005: Original Script
    0.11, 30 March 2005: Corrected script for error between Easter Sunday and Ascension Day		
    0.12, 31 May 2005: Corrected script for calculation of Advent and Trinity Sundays when Christmas falls on a Sunday
    0.13, 26 December 2005: Corrected script to announce Christmas octave between Christmas and First Sunday after Christmas	
    0.14, 19 May 2006: Moved Circumcision to the "Feast Day" list; Added Feasts of St. Barnabas, the Transfiguration, U.S. Independence Day, U.S. Thanksgiving Day
    0.15, 27 December 2008: Corrected problem with next year's Epiphany Sunday being used to compute First Sunday After Christmas
    0.16, 1 January 2009: Added current date callout before announcing liturgical celebration
*/					
// Define this day and this year
					$thisyear = date("Y");
					$thisday = unixtojd();
// Define ordinals					
					$ordinal = array (
					1 => "First",
					2 => "Second",
					3 => "Third",
					4 => "Fourth",
					5 => "Fifth",
					6 => "Sixth",
					7 => "Seventh",
					8 => "Eighth",
					9 => "Ninth",
					10 => "Tenth",
					11 => "Eleventh",
					12 => "Twelth",
					13 => "Thirteenth",
					14 => "Fourteenth",
					15 => "Fifteenth",
					16 => "Sixteenth",
					17 => "Seventeenth",
					18 => "Eighteenth",
					19 => "Nineteenth",
					20 => "Twentieth",
					21 => "Twenty-First",
					22 => "Twenty-Second",
					23 => "Twenty-Third",
					24 => "Twenty-Fourth",
					25 => "Twenty-Fifth",
					26 => "Twenty-Sixth",
					27 => "Twenty-Seventh"
					);
// Set Chrismas Day--if January, use last years day, otherwise use this years day					
					if (date("n") == 1) {
					$christmas[0] = gregoriantojd (12, 25, $thisyear - 1);
					}
					else {
					$christmas[0] = gregoriantojd (12, 25, $thisyear);
					}
// Find out what day of the week Christmas falls on					
					$christmasdayweek = jddayofweek ($christmas[0],0);
// Set Fourth Sunday in Advent; then all Sundays back to Sunday Before Advent are set from that					
					if ($christmasdayweek == 0) {
					$advent[4] = $christmas[0] - 7;
					}
					else {
					$advent[4] = $christmas[0] - $christmasdayweek;
					}
					$advent[0] = $advent[4] - 28;
					$advent[1] = $advent[4] - 21;
					$advent[2] = $advent[4] - 14;
					$advent[3] = $advent[4] - 7;
// Set Sundays after Christmas, Epiphany and Sundays After Epiphany					
					$christmas[1] = $christmas[0] + 7 - $christmasdayweek;
					$christmas[2] = $christmas[1] + 7;
					$epiphany = array (
					0 => gregoriantojd(1,6,$thisyear),
					1 => gregoriantojd(1,6,$thisyear) + 7 - jddayofweek(gregoriantojd(1,6,$thisyear)),
					2 => gregoriantojd(1,6,$thisyear) + 14 - jddayofweek(gregoriantojd(1,6,$thisyear)),
					3 => gregoriantojd(1,6,$thisyear) + 21 - jddayofweek(gregoriantojd(1,6,$thisyear)),
					4 => gregoriantojd(1,6,$thisyear) + 28 - jddayofweek(gregoriantojd(1,6,$thisyear)),
					5 => gregoriantojd(1,6,$thisyear) + 35 - jddayofweek(gregoriantojd(1,6,$thisyear)),
					6 => gregoriantojd(1,6,$thisyear) + 42 - jddayofweek(gregoriantojd(1,6,$thisyear))
					);
// Set Epiphany year forward for calcuation of Sundays after Christmas (override)
                    if (date("n") == 12) {
                    $epiphany[0] = gregoriantojd(1,6,$thisyear + 1);
                    }
// Set Sundays after Easter					
					$easter = array (
					0 => unixtojd(easter_date($thisyear)),
					1 => unixtojd(easter_date($thisyear)) + 7,
					2 => unixtojd(easter_date($thisyear)) + 14,
					3 => unixtojd(easter_date($thisyear)) + 21,
					4 => unixtojd(easter_date($thisyear)) + 28,
					5 => unixtojd(easter_date($thisyear)) + 35
					);
// Set Sundays in Lent, including Ash Wednesday	
					$lent = array (
					0 => $easter[0] - 46,
					1 => $easter[0] - 42,
					2 => $easter[0] - 35,
					3 => $easter[0] - 28,
					4 => $easter[0] - 21,
					5 => $easter[0] - 14,
					6 => $easter[0] - 7,
					);
// Set Pre-Lent Sundays, Ascension Days and Whitsunday					
					$quinquagesima = $easter[0] - 49;
					$sexagesima = $easter[0] - 56;
					$septuagesima = $easter[0] - 63;
					$ascension = $easter[0] + 39;
					$ascensionsunday = $easter[0] + 42;
					$whitsunday = $easter[0] + 49;
// Set Trinity Sunday					
					$trinity[0] = $easter[0] + 56;
// Compute Thanksgiving Day (U.S.)
                    $allsaints = gregoriantojd (11, 1, $thisyear);
                    $allsaintsdayweek = jddayofweek ($allsaints, 0);
                    switch ($allsaintsdayweek) {
                    case 5:
                    $thanksgiving = gregoriantojd (11, 28, $thisyear);
                    break;
                    case 6:
                    $thanksgiving = gregoriantojd (11, 27, $thisyear);
                    break;
                    default:
                    $thanksgiving = $allsaints + 4 - $allsaintsdayweek + 21;
                    break;
                    }			
// Set variable that shows what Sunday (or octave) it actually is										
					if (($thisday >= $christmas[0]) AND ($thisday < $christmas[1])) {
					$litday = "Christmas Day or Octave";
					}
					elseif ($thisday == $lent[0]) {
					$litday = "Ash Wednesday";
					}
					elseif ($thisday == $easter[0] - 6) {
					$litday = "Monday before Easter";
					}
                    elseif ($thisday == $easter[0] - 5) {
					$litday = "Tuesday before Easter";
					}
					elseif ($thisday == $easter[0] - 4) {
					$litday = "Wednesday before Easter";
					}
					elseif ($thisday == $easter[0] - 3) {
					$litday = "Maundy Thursday";
					}
					elseif ($thisday == $easter[0] - 2) {
					$litday = "Good Friday";
					}
					elseif ($thisday == $easter[0] - 1) {
					$litday = "Easter Even";
					}
					elseif ($thisday == $easter[0] + 1) {
					$litday = "Monday in Easter Week";
					}
                    elseif ($thisday == $easter[0] + 2) {
					$litday = "Tuesday in Easter Week";
					}
					elseif (($thisday < $epiphany[0]) AND ($thisday >= $christmas[1])) {
					$numsunday = intval(floor(($thisday - $christmas[1])/7)+1);
					$litday = $ordinal[$numsunday] . " Sunday after Christmas";
					}
					elseif (($thisday < $epiphany[1]) AND ($thisday >= $epiphany[0])) {
					$litday = "Epiphany";
					}
					elseif (($thisday < $septuagesima) AND ($thisday >= $epiphany[1])) {
					$numsunday = intval(floor(($thisday - $epiphany[1])/7)+1);
					$litday = $ordinal[$numsunday] . " Sunday after Epiphany";
					}
					elseif (($thisday < $sexagesima) AND ($thisday >= $septuagesima)) {
					$litday = "Septuagesima";
					}
					elseif (($thisday < $quinquagesima) AND ($thisday >= $sexagesima)) {
					$litday = "Sexagesima";
					}
					elseif (($thisday < $lent[0]) AND ($thisday >= $quinquagesima)) {
					$litday = "Quinquagesima";
					}
					elseif (($thisday < $lent[1]) AND ($thisday > $lent[0])) {
					$litday = "Ash Wednesday";
					}
					elseif (($thisday < $easter[0]) AND ($thisday >= $lent[1])) {
					$numsunday = intval(floor(($thisday - $lent[1])/7)+1);
					if ($numsunday == 6) {
					$litday = "Palm Sunday";
					}
					elseif ($numsunday == 5) {
					$litday = "Passion Sunday";
					}
					else {
					$litday = $ordinal[$numsunday] . " Sunday in Lent";
					}
					}
					elseif (($thisday < $ascension) AND ($thisday >= $easter[0])) {
					$numsunday = intval(floor(($thisday - $easter[0])/7));
					if ($numsunday == 0) {
					$litday = "Easter Sunday";
					}
					else {
					$litday = $ordinal[$numsunday] . " Sunday after Easter";
					}
					}
					elseif (($thisday < $ascensionsunday) AND ($thisday >= $ascension)) {
					$litday = "Ascension Day";
					}
					elseif (($thisday < $whitsunday) AND ($thisday >= $ascensionsunday)) {
					$litday = "Sunday after Ascension";
					}
					elseif (($thisday < $trinity[0]) AND ($thisday >= $whitsunday)) {
					$litday = "Whitsunday";
					}
					elseif (($thisday < $advent[0]) AND ($thisday >= $trinity[0])) {
					$numsunday = intval(floor(($thisday - $trinity[0])/7));
					if ($numsunday == 0) {
					$litday = "Trinity Sunday";
					}
					else {
					$litday = $ordinal[$numsunday] . " Sunday after Trinity";
					}
					}
					elseif (($thisday < $christmas[0]) AND ($thisday >= $advent[0])) {
					$numsunday = intval(floor(($thisday - $advent[0])/7));
					if ($numsunday == 0) {
					$litday = "Sunday before Advent";
					}
					else {
					$litday = $ordinal[$numsunday] . " Sunday in Advent";
					}
					}
// Set Saint or Feast Day			
					if ($thisday == gregoriantojd (1,  1, $thisyear)) {
					$feastday = "Circumcision";
					}
					elseif ($thisday == gregoriantojd (1, 25, $thisyear)) {
					$feastday = "Conversion of St. Paul";
					}
					elseif ($thisday == gregoriantojd (2, 2, $thisyear)) {
					$feastday = "Purification of the Virgin Mary";
					}
					elseif ($thisday == gregoriantojd (2, 24, $thisyear)) {
					$feastday = "Feast of St. Mathias";
					}
					elseif ($thisday == gregoriantojd (3, 25, $thisyear)) {
					$feastday = "Annunciation of the Virgin Mary";
					}
					elseif ($thisday == gregoriantojd (4, 25, $thisyear)) {
					$feastday = "Feast of St. Mark";
					}
					elseif ($thisday == gregoriantojd (5, 1, $thisyear)) {
					$feastday = "Feast of St. Phillip and St. James";
					}
					elseif ($thisday == gregoriantojd (6, 11, $thisyear)) {
					$feastday = "Feast of St. Barnabas";
					}
					elseif ($thisday == gregoriantojd (6, 24, $thisyear)) {
					$feastday = "Feast of St. John the Baptist";
					}
					elseif ($thisday == gregoriantojd (6, 29, $thisyear)) {
					$feastday = "Feast of St. Peter";
					}
					elseif ($thisday == gregoriantojd (7, 4, $thisyear)) {
					$feastday = "Independence Day (U.S.)";
					}
					elseif ($thisday == gregoriantojd (7, 25, $thisyear)) {
					$feastday = "Feast of St. James";
					}
					elseif ($thisday == gregoriantojd (8, 6, $thisyear)) {
					$feastday = "Feast of The Transfiguration of Christ";
					}
					elseif ($thisday == gregoriantojd (8, 24, $thisyear)) {
					$feastday = "Feast of St. Bartholomew";
					}
					elseif ($thisday == gregoriantojd (9, 21, $thisyear)) {
					$feastday = "Feast of St. Matthew";
					}
					elseif ($thisday == gregoriantojd (9, 29, $thisyear)) {
					$feastday = "Feast of St. Michael and All Angels";
					}
					elseif ($thisday == gregoriantojd (10, 18, $thisyear)) {
					$feastday = "Feast of St. Luke";
					}
					elseif ($thisday == gregoriantojd (10, 28, $thisyear)) {
					$feastday = "Feast of St. Simon and St. Jude";
					}
					elseif ($thisday == $allsaints) {
					$feastday = "All Saints Day";
					}
					elseif ($thisday == $thanksgiving) {
					$feastday = "Thanksgiving Day (U.S.)";
					}
					elseif ($thisday == gregoriantojd (11, 30, $thisyear)) {
					$feastday = "Feast of St. Andrew";
					}
					elseif ($thisday == gregoriantojd (12, 21, $thisyear)) {
					$feastday = "Feast of St. Thomas";
					}
					elseif ($thisday == gregoriantojd (12, 26, $thisyear)) {
					$feastday = "Feast of St. Stephen";
					}
					elseif ($thisday == gregoriantojd (12, 27, $thisyear)) {
					$feastday = "Feast of St. John the Evangelist";
					}
					elseif ($thisday == gregoriantojd (12, 28, $thisyear)) {
					$feastday = "Holy Innocents Day";
					}
// Set Ember or Rogation Day					
					$fallemberstart = gregoriantojd (9, 14, $thisyear);
					for ($i = 0; $i <= 6; $i++) {
					$fallember = $fallemberstart + $i;
					if (jddayofweek ($fallember,0) == 3) break;
					}
					$winteremberstart = gregoriantojd (12, 13, $thisyear);
					for ($i = 0; $i <= 6; $i++) {
					$winterember = $winteremberstart + $i;
					if (jddayofweek ($winterember,0) == 3) break;
					}
					if (($thisday > $easter[5]) AND ($thisday < $ascension)) {
					$emberogation = "Rogation Day";
					}
					elseif ($thisday == $lent[1] + 3) {
					$emberogation = "Ember Day";
					}
					elseif ($thisday == $lent[1] + 5) {
					$emberogation = "Ember Day";
					}
					elseif ($thisday == $lent[1] + 6) {
					$emberogation = "Ember Day";
					}
					elseif ($thisday == $whitsunday + 3) {
					$emberogation = "Ember Day";
					}
					elseif ($thisday == $whitsunday + 5) {
					$emberogation = "Ember Day";
					}
					elseif ($thisday == $whitsunday + 6) {
					$emberogation = "Ember Day";
					}
                    elseif ($thisday == $fallember) {
                    $emberogation = "Ember Day";
                    }
                    elseif ($thisday == $fallember + 2) {
                    $emberogation = "Ember Day";
                    }
                    elseif ($thisday == $fallember + 3) {
                    $emberogation = "Ember Day";
                    }
                    elseif ($thisday == $winterember) {
                    $emberogation = "Ember Day";
                    }
                    elseif ($thisday == $winterember + 2) {
                    $emberogation = "Ember Day";
                    }
                    elseif ($thisday == $winterember + 3) {
                    $emberogation = "Ember Day";
                    }
				echo date('D jS M Y') . '<hr>';
				if (isset($litday)) {
				echo 'Liturgical Celebration:<br>' . $litday;
				}
				if (isset($feastday)) {
				echo '<br>' . $feastday;
				}
				if (isset($emberogation)) {
				echo '<br>' . $emberogation;
				}
					?></h3>
Return current item: Anglican Calendar Script