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

Documentation generated on Thu, 10 Apr 2008 20:00:10 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.