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.6 2006/10/22 22:14:10 quipo 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.6 2006/10/22 22:14:10 quipo 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.         * Friday of the 3rd week past Whitsun
  183.         */
  184.         $heartJesusDate     = new Date($whitsunDate);
  185.         $heartJesusDate->addSpan(new Date_Span('19, 0, 0, 0'));
  186.         $this->_addHoliday('heartJesus'$heartJesusDate'Heart of Jesus celebration');
  187.         
  188.        /**
  189.         * Johannis celebration
  190.         */
  191.         $this->_addHoliday('johannisCelebration'$this->_year . '-06-24''Johannis celebration');
  192.         
  193.        /**
  194.         * Petrus and Paulus
  195.         */
  196.         $this->_addHoliday('petrusAndPaulus'$this->_year . '-06-29''Petrus and Paulus');
  197.         
  198.        /**
  199.         * Ascension of Maria
  200.         */
  201.         $this->_addHoliday('mariaAscension'$this->_year . '-08-15''Ascension of Maria');
  202.         
  203.        /**
  204.         * Celebration of raising the Cross
  205.         */
  206.         $this->_addHoliday('crossRaising'$this->_year . '-09-14''Celebration of raising the Cross');
  207.         
  208.        /**
  209.         * Thanks Giving
  210.         * 
  211.         * Sunday past Michaelis (29. September)
  212.         */
  213.         $michaelisDate      = new Date($this->_year . '-09-29');
  214.         $dayOfWeek          $michaelisDate->getDayOfWeek();
  215.         $michaelisDate->addSpan(new Date_Span(sprintf('%d, 0, 0, 0'7 - $dayOfWeek)));
  216.         $thanksGivingDate   $michaelisDate;
  217.         $this->_addHoliday('thanksGiving'$thanksGivingDate'Thanks Giving');
  218.         
  219.        /**
  220.         * Kermis
  221.         *
  222.         * 3rd Sunday in October
  223.         */
  224.         $kermisDate         = new Date($this->_year . '-10-01');
  225.         $dayOfWeek          $kermisDate->getDayOfWeek();
  226.         if ($dayOfWeek != 0{
  227.             $kermisDate->addSpan(new Date_Span(sprintf('%d, 0, 0, 0'7 - $dayOfWeek)));
  228.         }
  229.         $kermisDate->addSpan(new Date_Span('14, 0, 0, 0'));
  230.         $this->_addHoliday('kermis'$kermisDate'Kermis');
  231.         
  232.        /**
  233.         * Reformation Day
  234.         */
  235.         $this->_addHoliday('reformationDay'$this->_year . '-10-31''Reformation Day');
  236.         
  237.        /**
  238.         * All Saints' Day
  239.         */
  240.         $this->_addHoliday('allSaintsDay'$this->_year . '-11-01''All Saints\' Day');
  241.         
  242.        /**
  243.         * All Souls' Day
  244.         */
  245.         $this->_addHoliday('allSoulsDay'$this->_year . '-11-02''All Souls\' Day');
  246.         
  247.        /**
  248.         * Martin's Day
  249.         */
  250.         $this->_addHoliday('martinsDay'$this->_year . '-11-11''Martin\'s Day');
  251.         
  252.        /**
  253.         * 4th Advent
  254.         */
  255.         $Advent4Date        = new Date($this->_year . '-12-25');
  256.         $dayOfWeek          $Advent4Date->getDayOfWeek();
  257.         if ($dayOfWeek == 0{
  258.             $dayOfWeek      = 7;
  259.         }
  260.         $Advent4Date->subtractSpan(new Date_Span(sprintf('%d, 0, 0, 0'$dayOfWeek)));
  261.         $this->_addHoliday('advent4'$Advent4Date'4th Advent');
  262.         
  263.        /**
  264.         * 1st Advent
  265.         */
  266.         $Advent1Date        = new Date($Advent4Date);
  267.         $Advent1Date->subtractSpan(new Date_Span('21, 0, 0, 0'));
  268.         $this->_addHoliday('advent1'$Advent1Date'1st Advent');
  269.         
  270.        /**
  271.         * 2nd Advent
  272.         */
  273.         $Advent2Date        = new Date($Advent4Date);
  274.         $Advent2Date->subtractSpan(new Date_Span('14, 0, 0, 0'));
  275.         $this->_addHoliday('advent2'$Advent2Date'2nd Advent');
  276.         
  277.        /**
  278.         * 3rd Advent
  279.         */
  280.         $Advent3Date        = new Date($Advent4Date);
  281.         $Advent3Date->subtractSpan(new Date_Span('7, 0, 0, 0'));
  282.         $this->_addHoliday('advent3'$Advent3Date'3rd Advent');
  283.         
  284.        /**
  285.         * Death' Sunday
  286.         */
  287.         $deathSundayDate    = new Date($Advent1Date);
  288.         $deathSundayDate->subtractSpan(new Date_Span('7, 0, 0, 0'));
  289.         $this->_addHoliday('deathSunday'$deathSundayDate'Death\' Sunday');
  290.         
  291.        /**
  292.         * Day of Repentance
  293.         */
  294.         $dayOfRepentance    = new Date($deathSundayDate);
  295.         $dayOfRepentance->subtractSpan(new Date_Span('4, 0, 0, 0'));
  296.         $this->_addHoliday('dayOfRepentance'$dayOfRepentance'Day of Repentance');
  297.         
  298.        /**
  299.         * St. Nicholas' Day
  300.         */
  301.         $this->_addHoliday('stNicholasDay'$this->_year . '-12-06''St. Nicholas\' Day');
  302.         
  303.        /**
  304.         * Maria' conception
  305.         */
  306.         $this->_addHoliday('mariaConception'$this->_year . '-12-08''Conception of Maria');
  307.         
  308.        /**
  309.         * Christmas Eve
  310.         */
  311.         $this->_addHoliday('xmasEve'$this->_year . '-12-24''Christmas Eve');
  312.         
  313.        /**
  314.         * Christmas day
  315.         */
  316.         $this->_addHoliday('xmasDay'$this->_year . '-12-25''Christmas Day');
  317.         
  318.        /**
  319.         * Boxing day
  320.         */
  321.         $this->_addHoliday('boxingDay'$this->_year . '-12-26''Boxing Day');
  322.         
  323.        /**
  324.         * New Year's Eve
  325.         */
  326.         $this->_addHoliday('newYearsEve'$this->_year . '-12-31''New Year\'s Eve');
  327.         
  328.         if (Date_Holidays::errorsOccurred()) {
  329.             return Date_Holidays::getErrorStack();
  330.         }
  331.         return true;
  332.     }
  333.     
  334.    /**
  335.     * Calculates date for Easter using the Gaussian algorithm.
  336.     *
  337.     * @static
  338.     * @access   public
  339.     * @param    int     $year   year
  340.     * @return   object Date 
  341.     */
  342.     function calcEaster($year)
  343.     {
  344.         // golden number
  345.         $golden     = null;
  346.         $century    = null;
  347.         // 23-Epact (modulo 30)
  348.         $epact      = null;
  349.         // number of days from 21 March to the Paschal Full Moon
  350.         $i          = null;
  351.         // weekday of the Full Moon (0=Sunday,...)
  352.         $j          = null; 
  353.         
  354.         if ($year > 1582{
  355.             $golden     $year % 19;
  356.             $century    floor($year / 100);
  357.             $epact      ($century floor($century / 4floor((8 * $century + 13/ 25)+ 19 * $golden + 15% 30;
  358.             $i          $epact floor($epact / 28(1 - floor($epact / 28floor(29 / ($epact + 1)) floor((21 - $golden/ 11));
  359.             $j          ($year floor($year / 4$i + 2 - $century floor($century / 4));
  360.             $j          $j % 7;
  361.         else {
  362.             $golden $year % 19;
  363.             $i      (19 * $golden + 15% 30; 
  364.             $j      ($year floor($year / 4$i% 7;
  365.         }
  366.         $l      $i $j;
  367.         $month  = 3 + floor(($l + 40/ 44);
  368.         $day    $l + 28 - 31 * floor($month / 4);
  369.         
  370.         $date = new Date(sprintf('%04d-%02d-%02d'$year$month$day));
  371.         return $date;
  372.     }
  373. }
  374. ?>

Documentation generated on Mon, 11 Mar 2019 15:03:06 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.