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

Source for file creating_drivers.php

Documentation is available at creating_drivers.php

  1. <?php
  2. /**
  3.  * Example how to create an own driver-class for Date_Holidays
  4.  *
  5.  * To test this class, you have to copy it into the drivers-directory.
  6.  *
  7.  * The classname has to be something like Date_Holidays_Driver_*.
  8.  * Otherwise it won't be compatible to be used within PEAR's strict directory
  9.  * structure.
  10.  *
  11.  * PHP Version 5
  12.  *
  13.  * @category Date
  14.  * @package  Date_Holidays
  15.  * @author   Carsten Lucke <luckec@tool-garage.de>
  16.  * @license  http://www.php.net/license/3_01.txt PHP License 3.0.1
  17.  * @link     http://pear.php.net/package/Date_Holidays
  18.  */
  19. {
  20.     /**
  21.      * Constructor
  22.      *
  23.      * Use the Date_Holidays::factory() method to construct an object of a
  24.      * certain driver
  25.      *
  26.      * @access   protected
  27.      */
  28.     function Date_Holidays_Driver_Example()
  29.     {
  30.     }
  31.  
  32.     /**
  33.      * Build the internal arrays that contain data about the calculated holidays
  34.      *
  35.      * @access   protected
  36.      * @return   boolean true on success, otherwise a PEAR_ErrorStack object
  37.      * @throws   object PEAR_ErrorStack
  38.      */
  39.     function _buildHolidays()
  40.     {
  41.         /**
  42.          * If your driver is extending another driver-class and is not a direct
  43.          * descendant of the Date_Holidays_Driver base-class you will want to
  44.          * build this classes' holidays before you start with your turn.
  45.          *
  46.          * So just call the _buildHolidays() method of that class.
  47.          */
  48.         parent::_buildHolidays();
  49.  
  50.         /**
  51.          * There are two methods to add a holiday. One for adding holidays in
  52.          * general and on that can be used to add static holidays (every year
  53.          * the same day).
  54.          *
  55.          * You always have to give the added holiday an unique internal name
  56.          * within your driver.
  57.          * This should describe the holiday as good as possible.
  58.          *
  59.          * Of course you need a date and a title (the default title should
  60.          * always be in English)
  61.          *
  62.          * You can add as many translations as you want for your driver's
  63.          * holidays.
  64.          * Although the default title is in English you should add another one
  65.          * with the correct locale setting.
  66.          */
  67.  
  68.         /*
  69.          * General method to add a holiday
  70.          */
  71.  
  72.         // a static holiday
  73.         $this->_addHoliday('jesusCircumcision',
  74.                            $this->_year . '-01-01',
  75.                            'Circumcision of Jesus');
  76.  
  77.         // a calculated holiday
  78.         // if you are using helper methods to calculate movable holidays is
  79.         // your own decision
  80.         $fooDate $this->_calcFirstMondayInJanuary();
  81.         $this->_addHoliday('firstMondayInJan',
  82.                            $fooDate,
  83.                            'First monday in January');
  84.  
  85.         /*
  86.          * Special method for adding static holidays:
  87.          */
  88.         $static = array('newYearsDay' => array('date'  => '01-01',
  89.                                                'title' => 'New Year\'s Day'),
  90.                         'valentinesDay'   => array('date' => '02-14',
  91.                                               'title' => 'Valentine\'s Day'));
  92.         $this->_addStaticHolidays($static);
  93.         if (Date_Holidays::errorsOccurred()) {
  94.             return Date_Holidays::getErrorStack();
  95.         }
  96.         return true;
  97.     }
  98.  
  99.     /**
  100.      * A helper method
  101.      *
  102.      * @access   private
  103.      * @return   object Date date of first monday in actual years january
  104.      */
  105.     function _calcFirstMondayInJanuary()
  106.     {
  107.         $date = new Date($this->_year . '-01-01');
  108.         while ($date->getDayOfWeek(!= 1{
  109.             $date $date->getNextDay();
  110.         }
  111.         return $date;
  112.     }
  113. }
  114. ?>

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