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

Source for file EasternChristian.php

Documentation is available at EasternChristian.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. /**
  4.  * Driver for Eastern 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   Ken Guest <ken@linux.ie>
  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 Eastern Christian holidays
  28.  *
  29.  * @category   Date
  30.  * @package    Date_Holidays
  31.  * @subpackage Driver
  32.  * @author     Ken Guest <ken@linux.ie>
  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 = 'EasternChristian';
  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.     {
  55.     }
  56.  
  57.     /**
  58.      * Build the internal arrays that contain data about the calculated holidays
  59.      *
  60.      * @access   protected
  61.      * @return   boolean true on success, otherwise a PEAR_ErrorStack object
  62.      * @throws   object PEAR_ErrorStack
  63.      */
  64.     function _buildHolidays()
  65.     {
  66.         $year $this->_year;
  67.  
  68.         /**
  69.          * Circumcision of Jesus
  70.          */
  71.         $this->_addHoliday('jesusCircumcision',
  72.                            $year '-01-01',
  73.                            'Circumcision of Jesus');
  74.  
  75.         /**
  76.          * Epiphanias
  77.          */
  78.         $this->_addHoliday('epiphany'$year '-01-06''Epiphany');
  79.  
  80.         /**
  81.          * Cleaning of MariƤ
  82.          */
  83.         $this->_addHoliday('mariaCleaning',
  84.                            $year '-02-02',
  85.                            'Cleaning of Maria');
  86.  
  87.         /**
  88.          * Josef's Day
  89.          */
  90.         $this->_addHoliday('josefsDay',
  91.                            $year '-03-19',
  92.                            'Josef\'s Day');
  93.  
  94.         /**
  95.          * Maria Announcement
  96.          */
  97.         $this->_addHoliday('mariaAnnouncement',
  98.                             $year '-03-25',
  99.                             'Maria Announcement');
  100.  
  101.         /**
  102.          * Easter Sunday
  103.          */
  104.         $easterDate Date_Holidays_Driver_EasternChristian::calcEaster($year);
  105.         $this->_addHoliday('easter'$easterDate'Easter Sunday');
  106.  
  107.         /**
  108.          * Palm Sunday
  109.          */
  110.         $palmSundayDate $this->_addDays($easterDate-7);
  111.         $this->_addHoliday('palmSunday'$palmSundayDate'Palm Sunday');
  112.  
  113.         /**
  114.          * Passion Sunday
  115.          */
  116.         $passionSundayDate = new Date($palmSundayDate);
  117.         #$passionSundayDate->subtractSpan(new Date_Span('7, 0, 0, 0'));
  118.         $passionSundayDate $this->_addDays($palmSundayDate-7);
  119.         $this->_addHoliday('passionSunday'$passionSundayDate'Passion Sunday');
  120.  
  121.         /**
  122.          * Painful Friday
  123.          */
  124.         #$painfulFridayDate = new Date($palmSundayDate);
  125.         #$painfulFridayDate->subtractSpan(new Date_Span('2, 0, 0, 0'));
  126.         $painfulFridayDate $this->_addDays($palmSundayDate-2);
  127.         $this->_addHoliday('painfulFriday'$painfulFridayDate'Painful Friday');
  128.  
  129.         /**
  130.          * White Sunday
  131.          */
  132.         #$whiteSundayDate = new Date($easterDate);
  133.         #$whiteSundayDate->addSpan(new Date_Span('7, 0, 0, 0'));
  134.         $whiteSundayDate $this->_addDays($easterDate7);
  135.         $this->_addHoliday('whiteSunday'$whiteSundayDate'White Sunday');
  136.  
  137.         /**
  138.          * Ash Wednesday
  139.          */
  140.         #$ashWednesdayDate = new Date($easterDate);
  141.         #$ashWednesdayDate->subtractSpan(new Date_Span('46, 0, 0, 0'));
  142.         $ashWednesdayDate $this->_addDays($easterDate-46);
  143.         $this->_addHoliday('ashWednesday'$ashWednesdayDate'Ash Wednesday');
  144.  
  145.         /**
  146.          * Good Friday / Black Friday
  147.          */
  148.         #$goodFridayDate = new Date($easterDate);
  149.         #$goodFridayDate->subtractSpan(new Date_Span('2, 0, 0, 0'));
  150.         $goodFridayDate $this->_addDays($easterDate-2);
  151.         $this->_addHoliday('goodFriday'$goodFridayDate'Good Friday');
  152.  
  153.         /**
  154.          * Green Thursday
  155.          */
  156.         $this->_addHoliday('greenThursday',
  157.                            $goodFridayDate->getPrevDay(),
  158.                            'Green Thursday');
  159.  
  160.         /**
  161.          * Easter Monday
  162.          */
  163.         $this->_addHoliday('easterMonday',
  164.                            $easterDate->getNextDay(),
  165.                            'Easter Monday');
  166.  
  167.         /**
  168.          * Triytsia
  169.          */
  170.         #$triyDate = new Date($easterDate);
  171.         #$triyDate->addSpan(new Date_Span('49, 0, 0, 0'));
  172.         $triyDate $this->_addDays($easterDate49);
  173.  
  174.         $this->_addHoliday('Triytsia'$triyDate'Triytsia');
  175.  
  176.         if (Date_Holidays::errorsOccurred()) {
  177.             return Date_Holidays::getErrorStack();
  178.         }
  179.         return true;
  180.     }
  181.  
  182.     /**
  183.      * Calculates date for Easter using the Gaussian algorithm.
  184.      *
  185.      * @param int $year year
  186.      *
  187.      * @static
  188.      * @access   public
  189.      * @return   object Date 
  190.      */
  191.     function calcEaster($year)
  192.     {
  193.         //Use A variation of Gauss' algorithm
  194.         //http://www.smart.net/~mmontes/ortheast.html
  195.         $julianOffset = 13;
  196.         if ($year > 2100{
  197.             $julianOffset = 14;
  198.         }
  199.         $a  $year % 19;
  200.         $b  $year % 4;
  201.         $c  $year % 7;
  202.         $ra (19 * $a + 16);
  203.         $r4 $ra % 30;
  204.         $rb = 2 * $b + 4 * $c + 6 * $r4;
  205.         $r5 $rb % 7;
  206.         $rc $r4 $r5 $julianOffset;
  207.  
  208.         $offset = new Date("$year-03-21");
  209.         #$offset->addSpan(new Date_Span("$rc, 0, 0, 0"));
  210.         $offset $this->_addDays($offset$rc);
  211.  
  212.         return $offset;
  213.     }
  214. }
  215. ?>

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