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

Documentation generated on Mon, 11 Mar 2019 13:54:58 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.