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

Source for file Ireland.php

Documentation is available at Ireland.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:   Ken Guest <ken@linux.ie>                                  |
  17. // +----------------------------------------------------------------------+
  18. //
  19. //    $Id: Ireland.php,v 1.2 2007/05/30 20:52:40 luckec Exp $
  20.  
  21. require_once 'Date/Holidays/Driver/Christian.php';
  22.  
  23. /**
  24.  * Driver class that calculates Irish holidays
  25.  * deriving most calculations from 'Public holidays in Ireland' document
  26.  * on http://www.citizensinformation.ie/
  27.  *
  28.  * @category    Date
  29.  * @package     Date_Holidays
  30.  * @subpackage  Driver
  31.  * @version     $Id: Ireland.php,v 1.2 2007/05/30 20:52:40 luckec Exp $
  32.  * @author      Ken Guest <ken.guest@ipartners.ie>
  33.  */
  34. {
  35.    /**
  36.     * Constructor
  37.     *
  38.     * Use the Date_Holidays::factory() method to construct an object of a certain driver
  39.     *
  40.     * @access   protected
  41.     */
  42.     function Date_Holidays_Driver_Ireland({}
  43.  
  44.    /**
  45.     * Build the internal arrays that contain data about the calculated holidays
  46.     *
  47.     * @access   protected
  48.     * @return   boolean true on success, otherwise a PEAR_ErrorStack object
  49.     * @throws   object PEAR_ErrorStack
  50.     */
  51.     function _buildHolidays()
  52.     {
  53.        /**
  54.         * New Year's Day
  55.         */
  56.         $this->_addHoliday('newYearsDay'$this->_year . '-01-01''New Year\'s Day');
  57.  
  58.        /**
  59.         * Epiphany
  60.         */
  61.         $this->_addHoliday('epiphany'$this->_year . '-01-06''Epiphany');
  62.  
  63.        /**
  64.         * St Patrick's Day.
  65.         */
  66.         $this->_addHoliday('stPatricksDay'$this->_year . '-03-17''Saint Patrick\'s Day');
  67.  
  68.        /**
  69.         * Easter Sunday
  70.         */
  71.         $easterDate Date_Holidays_Driver_Ireland::calcEaster($this->_year);
  72.         $this->_addHoliday('easter'$easterDate'Easter Sunday');
  73.  
  74.        /**
  75.         * Good Friday / Black Friday
  76.         */
  77.         $goodFridayDate = new Date($easterDate);
  78.         $goodFridayDate->subtractSpan(new Date_Span('2, 0, 0, 0'));
  79.         $this->_addHoliday('goodFriday'$goodFridayDate'Good Friday');
  80.  
  81.        /**
  82.         * Easter Monday
  83.         */
  84.         $this->_addHoliday('easterMonday'$easterDate->getNextDay()'Easter Monday');
  85.  
  86.        /**
  87.         * May Bank Holiday
  88.         */
  89.         $dn $this->_calcFirstMonday('05');
  90.         $this->_addHoliday('mayDayBankHoliday'$dn'May Bank Holiday');
  91.  
  92.        /**
  93.         * Pentecost (determines Whit Monday, Ascension Day and Feast of Corpus Christi)
  94.         */
  95.         $pentecostDate = new Date($easterDate);
  96.         $pentecostDate->addSpan(new Date_Span('49, 0, 0, 0'));
  97.         $this->_addHoliday('pentecost'$pentecostDate'Pentecost');
  98.  
  99.        /**
  100.         * Ascension Day
  101.         */
  102.         $ascensionDayDate = new Date($pentecostDate);
  103.         $ascensionDayDate->subtractSpan(new Date_Span('10, 0, 0, 0'));
  104.         $this->_addHoliday('ascensionDay'$ascensionDayDate'Ascension Day');
  105.  
  106.        /**
  107.         * June Bank Holiday
  108.         */
  109.         $dn $this->_calcFirstMonday('06');
  110.         $this->_addHoliday('juneBankHoliday'$dn'June Bank Holiday');
  111.  
  112.        /**
  113.         * Midsummer
  114.         * Saturday past 20th, June
  115.         */
  116.         $juneDate       = new Date($this->_year . '-06-20');
  117.         $dayOfWeek      $juneDate->getDayOfWeek();
  118.         $juneDate->addSpan(new Date_Span(sprintf('%d, 0, 0, 0'6 - $dayOfWeek)));
  119.         $midSummerDate  $juneDate;
  120.         $this->_addHoliday('midSummer'$midSummerDate'Midsummer Day');
  121.         
  122.        /**
  123.         * August Bank Holiday
  124.         */
  125.         $dn $this->_calcFirstMonday('08');
  126.         $this->_addHoliday('augustBankHoliday'$dn'August Bank Holiday');
  127.  
  128.        /**
  129.         * October Bank Holiday
  130.         */
  131.         $dn $this->_calcLastMonday('10');
  132.         $this->_addHoliday('octoberBankHoliday'$dn'October Bank Holiday');
  133.  
  134.        /**
  135.         * Christmas Eve
  136.         */
  137.         $this->_addHoliday('xmasEve'$this->_year . '-12-24''Christmas Eve');
  138.  
  139.        /**
  140.         * Christmas day
  141.         */
  142.         $this->_addHoliday('xmasDay'$this->_year . '-12-25''Christmas Day');
  143.  
  144.        /**
  145.         * Boxing day
  146.         */
  147.         $this->_addHoliday('boxingDay'$this->_year . '-12-26''Boxing Day');
  148.  
  149.        /**
  150.         * New Year's Eve
  151.         */
  152.         $this->_addHoliday('newYearsEve'$this->_year . '-12-31''New Year\'s Eve');
  153.  
  154.         if (Date_Holidays::errorsOccurred()) {
  155.             return Date_Holidays::getErrorStack();
  156.         }
  157.         return true;
  158.     }
  159.  
  160.    /**
  161.     * Calculates the date for Easter. Actually this methods delegates the calculation to
  162.     * the {@link Date_Holidays_Driver_Christian#calcEaster()} method.
  163.     *
  164.     * @static
  165.     * @access   private
  166.     * @param    int     $year   year
  167.     * @return   object Date 
  168.     */
  169.     function calcEaster($year)
  170.     {
  171.         return Date_Holidays_Driver_Christian::calcEaster($year);
  172.     }
  173.     
  174.    /**
  175.     * Method that returns an array containing the ISO3166 codes that may possibly
  176.     * identify a driver.
  177.     * 
  178.     * @static
  179.     * @access public
  180.     * @return array possible ISO3166 codes
  181.     */
  182.     function getISO3166Codes(
  183.     {
  184.         return array('ie''irl');
  185.     }
  186.    /**
  187.     * A helper method
  188.     *
  189.     * @access   private
  190.     * @param    integer     month
  191.     * @return   object Date date of first monday in specified month.
  192.     */
  193.     function _calcFirstMonday($month
  194.     {
  195.         $date   = new Date($this->_year . "-$month-01");
  196.         while ($date->getDayOfWeek(!= 1{
  197.             $date   $date->getNextDay();
  198.         }
  199.         return ($date);
  200.     }
  201.    /**
  202.     * A helper method
  203.     *
  204.     * @access   private
  205.     * @param    integer     month
  206.     * @return   object Date date of last monday in specified month.
  207.     */
  208.     function _calcLastMonday($month
  209.     {
  210.         //work backwards from the first day of the next month.
  211.         $nm ((int) $month + 1;
  212.         if ($nm > 12{
  213.             $nm = 1;
  214.         }
  215.         $date   = new Date($this->_year . "-$nm-01");
  216.         $date   $date->getPrevDay();
  217.         while ($date->getDayOfWeek(!= 1{
  218.             $date   $date->getPrevDay();
  219.         }
  220.         return ($date);
  221.     }
  222. }
  223. ?>

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