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

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