Date_Holidays
[ class tree: Date_Holidays ] [ index: Date_Holidays ] [ all elements ]

Source for file Christian.php

Documentation is available at Christian.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. /**
  4.  * Driver for Christian holidays
  5.  *
  6.  * PHP Version 5
  7.  *
  8.  * Copyright (c) 1997-2008 The PHP Group
  9.  *
  10.  * This source file is subject to version 3.0 of the PHP license,
  11.  * that is bundled with this package in the file LICENSE, and is
  12.  * available at through the world-wide-web at
  13.  * http://www.php.net/license/3_01.txt.
  14.  * If you did not receive a copy of the PHP license and are unable to
  15.  * obtain it through the world-wide-web, please send a note to
  16.  * license@php.net so we can mail you a copy immediately.
  17.  *
  18.  * @category Date
  19.  * @package  Date_Holidays
  20.  * @author   Carsten Lucke <luckec@tool-garage.de>
  21.  * @license  http://www.php.net/license/3_01.txt PHP License 3.0.1
  22.  * @version  CVS: $Id$
  23.  * @link     http://pear.php.net/package/Date_Holidays
  24.  */
  25.  
  26. /**
  27.  * class that calculates Christian holidays
  28.  *
  29.  * @category   Date
  30.  * @package    Date_Holidays
  31.  * @subpackage Driver
  32.  * @author     Carsten Lucke <luckec@tool-garage.de>
  33.  * @license    http://www.php.net/license/3_01.txt PHP License 3.0.1
  34.  * @version    CVS: $Id$
  35.  * @link       http://pear.php.net/package/Date_Holidays
  36.  */
  37. {
  38.     /**
  39.      * this driver's name
  40.      *
  41.      * @access   protected
  42.      * @var      string 
  43.      */
  44.     var $_driverName = 'Christian';
  45.  
  46.     /**
  47.      * Constructor
  48.      *
  49.      * Use the Date_Holidays::factory() method to construct an object of a
  50.      * certain driver
  51.      *
  52.      * @access   protected
  53.      */
  54.     function Date_Holidays_Driver_Christian()
  55.     {
  56.     }
  57.  
  58.     /**
  59.      * Build the internal arrays that contain data about the calculated holidays
  60.      *
  61.      * @access   protected
  62.      * @return   boolean true on success, otherwise a PEAR_ErrorStack object
  63.      * @throws   object PEAR_ErrorStack
  64.      */
  65.     function _buildHolidays()
  66.     {
  67.         /**
  68.          * Circumcision of Jesus
  69.          */
  70.         $this->_addHoliday('jesusCircumcision',
  71.                            $this->_year . '-01-01',
  72.                            'Circumcision of Jesus');
  73.  
  74.         /**
  75.          * Epiphanias
  76.          */
  77.         $this->_addHoliday('epiphany'$this->_year . '-01-06''Epiphany');
  78.  
  79.         /**
  80.          * Cleaning of MariƤ
  81.          */
  82.         $this->_addHoliday('mariaCleaning',
  83.                            $this->_year . '-02-02',
  84.                            'Cleaning of Maria');
  85.  
  86.         /**
  87.          * Josef's Day
  88.          */
  89.         $this->_addHoliday('josefsDay',
  90.                            $this->_year . '-03-19',
  91.                            'Josef\'s Day');
  92.  
  93.         /**
  94.          * Maria Announcement
  95.          */
  96.         $this->_addHoliday('mariaAnnouncement',
  97.                             $this->_year . '-03-25',
  98.                             'Maria Announcement');
  99.  
  100.         /**
  101.          * Easter Sunday
  102.          */
  103.         $easterDate Date_Holidays_Driver_Christian::calcEaster($this->_year);
  104.         $this->_addHoliday('easter'$easterDate'Easter Sunday');
  105.  
  106.         /**
  107.          * Palm Sunday
  108.          */
  109.         $palmSundayDate $this->_addDays($easterDate-7);
  110.         $this->_addHoliday('palmSunday'$palmSundayDate'Palm Sunday');
  111.  
  112.         /**
  113.          * Passion Sunday
  114.          */
  115.         $passionSundayDate $this->_addDays($palmSundayDate-7);
  116.         $this->_addHoliday('passionSunday'$passionSundayDate'Passion Sunday');
  117.  
  118.         /**
  119.          * Painful Friday
  120.          */
  121.         $painfulFridayDate $this->_addDays($palmSundayDate-2);
  122.         $this->_addHoliday('painfulFriday'$painfulFridayDate'Painful Friday');
  123.  
  124.         /**
  125.          * White Sunday
  126.          */
  127.         $whiteSundayDate $this->_addDays($easterDate7);
  128.         $this->_addHoliday('whiteSunday'$whiteSundayDate'White Sunday');
  129.  
  130.         /**
  131.          * Ash Wednesday
  132.          */
  133.         $ashWednesdayDate $this->_addDays($easterDate-46);
  134.         $this->_addHoliday('ashWednesday'$ashWednesdayDate'Ash Wednesday');
  135.  
  136.         /**
  137.          * Good Friday / Black Friday
  138.          */
  139.         $goodFridayDate $this->_addDays($easterDate-2);
  140.         $this->_addHoliday('goodFriday'$goodFridayDate'Good Friday');
  141.  
  142.         /**
  143.          * Green Thursday
  144.          */
  145.         $this->_addHoliday('greenThursday',
  146.                            $goodFridayDate->getPrevDay(),
  147.                            'Green Thursday');
  148.  
  149.         /**
  150.          * Easter Monday
  151.          */
  152.         $this->_addHoliday('easterMonday',
  153.                            $easterDate->getNextDay(),
  154.                            'Easter Monday');
  155.  
  156.         /**
  157.          * Whitsun (determines Whit Monday, Ascension Day and
  158.          * Feast of Corpus Christi)
  159.          */
  160.         $whitsunDate $this->_addDays($easterDate49);
  161.         $this->_addHoliday('whitsun'$whitsunDate'Whitsun');
  162.  
  163.         /**
  164.          * Request Sunday
  165.          */
  166.         $requestSunday $this->_addDays($whitsunDate-14);
  167.         $this->_addHoliday('requestSunday'$requestSunday'Request Sunday');
  168.  
  169.         /**
  170.          * Ascension Day
  171.          */
  172.         $ascensionDayDate $this->_addDays($whitsunDate-10);
  173.         $this->_addHoliday('ascensionDay'$ascensionDayDate'Ascension Day');
  174.  
  175.         /**
  176.          * Whit Monday
  177.          */
  178.         $this->_addHoliday('whitMonday'$whitsunDate->getNextDay()'Whit Monday');
  179.  
  180.         /**
  181.          * Haunting of MariƤ
  182.          */
  183.         $this->_addHoliday('mariaHaunting',
  184.                            $this->_year . '-05-31',
  185.                            'Haunting of Maria');
  186.  
  187.         /**
  188.          * Trinitatis
  189.          */
  190.         $trinitatisDate $this->_addDays($whitsunDate7);
  191.         $this->_addHoliday('trinitatis',
  192.                            $trinitatisDate,
  193.                            'Trinitatis');
  194.  
  195.         /**
  196.          * Feast of Corpus Christi
  197.          */
  198.         $corpusChristiDate $this->_addDays($whitsunDate11);
  199.         $this->_addHoliday('corpusChristi',
  200.                            $corpusChristiDate,
  201.                            'Feast of Corpus Christi');
  202.  
  203.         /**
  204.          * Heart of Jesus
  205.          *
  206.          * Friday of the 3rd week past Whitsun
  207.          */
  208.         $heartJesusDate $this->_addDays($whitsunDate19);
  209.         $this->_addHoliday('heartJesus',
  210.                            $heartJesusDate,
  211.                            'Heart of Jesus celebration');
  212.  
  213.         /**
  214.          * Johannis celebration
  215.          */
  216.         $this->_addHoliday('johannisCelebration',
  217.                            $this->_year . '-06-24',
  218.                            'Johannis celebration');
  219.  
  220.         /**
  221.          * Petrus and Paulus
  222.          */
  223.         $this->_addHoliday('petrusAndPaulus',
  224.                            $this->_year . '-06-29',
  225.                            'Petrus and Paulus');
  226.  
  227.         /**
  228.          * Ascension of Maria
  229.          */
  230.         $this->_addHoliday('mariaAscension',
  231.                            $this->_year . '-08-15',
  232.                            'Ascension of Maria');
  233.  
  234.         /**
  235.          * Celebration of raising the Cross
  236.          */
  237.         $this->_addHoliday('crossRaising',
  238.                            $this->_year . '-09-14',
  239.                            'Celebration of raising the Cross');
  240.  
  241.         /**
  242.          * Thanks Giving
  243.          *
  244.          * Sunday past Michaelis (29. September)
  245.          */
  246.         $michaelisDate = new Date($this->_year . '-09-29');
  247.         $dayOfWeek     $michaelisDate->getDayOfWeek();
  248.         $michaelisDate $this->_addDays($michaelisDate7 - $dayOfWeek);
  249.         $thanksGivingDate $michaelisDate;
  250.         $this->_addHoliday('thanksGiving'$thanksGivingDate'Thanks Giving');
  251.  
  252.         /**
  253.          * Kermis
  254.          *
  255.          * 3rd Sunday in October
  256.          */
  257.         $kermisDate = new Date($this->_year . '-10-01');
  258.         $dayOfWeek  $kermisDate->getDayOfWeek();
  259.         if ($dayOfWeek != 0{
  260.             $kermisDate $this->_addDays($kermisDate7 - $dayOfWeek);
  261.         }
  262.         $kermisDate $this->_addDays($kermisDate14);
  263.         $this->_addHoliday('kermis'$kermisDate'Kermis');
  264.  
  265.         /**
  266.          * Reformation Day
  267.          */
  268.         $this->_addHoliday('reformationDay',
  269.                            $this->_year . '-10-31',
  270.                            'Reformation Day');
  271.  
  272.         /**
  273.          * All Saints' Day
  274.          */
  275.         $this->_addHoliday('allSaintsDay',
  276.                            $this->_year . '-11-01',
  277.                            'All Saints\' Day');
  278.  
  279.         /**
  280.          * All Souls' Day
  281.          */
  282.         $this->_addHoliday('allSoulsDay',
  283.                             $this->_year . '-11-02',
  284.                             'All Souls\' Day');
  285.  
  286.         /**
  287.          * Martin's Day
  288.          */
  289.         $this->_addHoliday('martinsDay'$this->_year . '-11-11''Martin\'s Day');
  290.  
  291.         /**
  292.          * 4th Advent
  293.          */
  294.         $Advent4Date = new Date($this->_year . '-12-25');
  295.         $dayOfWeek   $Advent4Date->getDayOfWeek();
  296.         if ($dayOfWeek == 0{
  297.             $dayOfWeek = 7;
  298.         }
  299.         $Advent4Date $this->_addDays($Advent4Date-$dayOfWeek);
  300.         $this->_addHoliday('advent4'$Advent4Date'4th Advent');
  301.  
  302.         /**
  303.          * 1st Advent
  304.          */
  305.         $Advent1Date $this->_addDays($Advent4Date-21);
  306.         $this->_addHoliday('advent1'$Advent1Date'1st Advent');
  307.  
  308.         /**
  309.          * 2nd Advent
  310.          */
  311.         $Advent2Date $this->_addDays($Advent4Date-14);
  312.         $this->_addHoliday('advent2'$Advent2Date'2nd Advent');
  313.  
  314.         /**
  315.          * 3rd Advent
  316.          */
  317.         $Advent3Date $this->_addDays($Advent4Date-7);
  318.         $this->_addHoliday('advent3'$Advent3Date'3rd Advent');
  319.  
  320.         /**
  321.          * Death' Sunday
  322.          */
  323.         $deathSundayDate $this->_addDays($Advent1Date-7);
  324.         $this->_addHoliday('deathSunday'$deathSundayDate'Death\' Sunday');
  325.  
  326.         /**
  327.          * Day of Repentance
  328.          */
  329.         $dayOfRepentance $this->_addDays($deathSundayDate-4);
  330.         $this->_addHoliday('dayOfRepentance'$dayOfRepentance'Day of Repentance');
  331.  
  332.         /**
  333.          * St. Nicholas' Day
  334.          */
  335.         $this->_addHoliday('stNicholasDay',
  336.                            $this->_year . '-12-06',
  337.                            'St. Nicholas\' Day');
  338.  
  339.         /**
  340.          * Maria' conception
  341.          */
  342.         $this->_addHoliday('mariaConception',
  343.                            $this->_year . '-12-08',
  344.                            'Conception of Maria');
  345.  
  346.         /**
  347.          * Christmas Eve
  348.          */
  349.         $this->_addHoliday('christmasEve'$this->_year . '-12-24''Christmas Eve');
  350.  
  351.         /**
  352.          * Christmas day
  353.          */
  354.         $this->_addHoliday('christmasDay'$this->_year . '-12-25''Christmas Day');
  355.  
  356.         /**
  357.          * Boxing day
  358.          */
  359.         $this->_addHoliday('boxingDay'$this->_year . '-12-26''Boxing Day');
  360.  
  361.         /**
  362.          * New Year's Eve
  363.          */
  364.         $this->_addHoliday('newYearsEve',
  365.                            $this->_year . '-12-31',
  366.                            'New Year\'s Eve');
  367.  
  368.         if (Date_Holidays::errorsOccurred()) {
  369.             return Date_Holidays::getErrorStack();
  370.         }
  371.         return true;
  372.     }
  373.  
  374.     /**
  375.      * Calculates date for Easter using the Gaussian algorithm.
  376.      *
  377.      * @param int $year year
  378.      *
  379.      * @static
  380.      * @access   public
  381.      * @return   object Date 
  382.      */
  383.     function calcEaster($year)
  384.     {
  385.         if (function_exists("easter_days")) {
  386.             $easter = new Date();
  387.             $easter->setDate(
  388.                 strtotime("$year-03-21 + " . easter_days($year" days"),
  389.                 DATE_FORMAT_UNIXTIME
  390.             );
  391.             return $easter;
  392.         }
  393.         // golden number
  394.         $golden  = null;
  395.         $century = null;
  396.         // 23-Epact (modulo 30)
  397.         $epact = null;
  398.         // number of days from 21 March to the Paschal Full Moon
  399.         $i = null;
  400.         // weekday of the Full Moon (0=Sunday,...)
  401.         $j = null;
  402.  
  403.         if ($year > 1582{
  404.             $golden  $year % 19;
  405.             $century floor($year / 100);
  406.             $l       floor($century / 4);
  407.             $epact   ($century $l floor((8 * $century + 13/ 25)
  408.                         + 19 * $golden + 15% 30;
  409.             $i       $epact floor($epact / 28(1 - floor($epact / 28*
  410.                        floor(29 / ($epact + 1)) floor((21 - $golden/ 11));
  411.             $j       ($year floor($year / 4$i + 2 - $century $l);
  412.             $j       $j % 7;
  413.         else {
  414.             $golden $year % 19;
  415.             $i      (19 * $golden + 15% 30;
  416.             $j      ($year floor($year / 4$i% 7;
  417.         }
  418.         $l     $i $j;
  419.         $month = 3 + floor(($l + 40/ 44);
  420.         $day   $l + 28 - 31 * floor($month / 4);
  421.  
  422.         $date = new Date(sprintf('%04d-%02d-%02d'$year$month$day));
  423.         return $date;
  424.     }
  425. }
  426. ?>

Documentation generated on Tue, 22 Jan 2013 01:00:06 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.