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

Source for file USA.php

Documentation is available at USA.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:   Kevin English <kevin@x5dev.com>                           |
  17. // +----------------------------------------------------------------------+
  18. //
  19.  
  20.  
  21. /**
  22.  * class that calculates observed U.S. holidays
  23.  *
  24.  * @category    Date
  25.  * @package     Date_Holidays
  26.  * @subpackage  Driver
  27.  * @version     $Id: USA.php,v 1.4 2006/04/02 22:19:06 luckec Exp $
  28.  * @author      Kevin English <kevin@x5dev.com>
  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_USA()
  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.         * New Year's Day
  53.         */
  54.         $newYearsDay $this->_calcNearestWorkDay('01','01');
  55.         $this->_addHoliday('newYearsDay'$newYearsDay'New Year\'s Day');
  56.  
  57.         $thirdMondayInJanuaryDate  $this->_calcNthMondayInMonth(1,3);
  58.         $this->_addHoliday('mlkDay'$thirdMondayInJanuaryDate'Dr. Martin Luther King Jr\'s Birthday');
  59.  
  60.        /**
  61.         * President's Day
  62.         */
  63.         $thirdMondayInFebruaryDate  $this->_calcNthMondayInMonth(2,3);
  64.         $this->_addHoliday('presidentsDay'$thirdMondayInFebruaryDate'President\'s Day');
  65.  
  66.        /**
  67.         * Memorial Day
  68.         */
  69.         $lastMondayInMayDate $this->_calcLastMondayInMonth(5);
  70.         $this->_addHoliday('memorialDay',$lastMondayInMayDate,'Memorial Day');
  71.  
  72.        /**
  73.         * 4th of July
  74.         */
  75.         $independenceDay $this->_calcNearestWorkDay('07','04');
  76.         $this->_addHoliday('independenceDay',$independenceDay,'Independence Day');
  77.  
  78.        /**
  79.         * Labor Day
  80.         */
  81.         $laborDay $this->_calcNthMondayInMonth(9,1);
  82.         $this->_addHoliday('laborDay',$laborDay,'Labor Day');
  83.  
  84.        /**
  85.         * Columbus Day
  86.         */
  87.         $columbusDay $this->_calcNthMondayInMonth(10,2);
  88.         $this->_addHoliday('columbusDay',$columbusDay,'Columbus Day');
  89.  
  90.        /**
  91.         * Veteran's  Day
  92.         */
  93.         $this->_addHoliday('veteransDay',$this->_year.'-11-11','Veteran\'s Day');
  94.  
  95.        /**
  96.         * Thanksgiving  Day
  97.         */
  98.         $tday$this->_calcNthThursdayInMonth(11,4);
  99.         $this->_addHoliday('thanksgivingDay',$tday,'Thanksgiving Day');
  100.  
  101.        /**
  102.         * Christmas  Day
  103.         */
  104.         $cday$this->_calcNearestWorkDay('12','25');
  105.         $this->_addHoliday('christmasDay',$cday,'Christmas Day');
  106.  
  107.         return true;
  108.     }
  109.  
  110.    /**
  111.     * Calculate Nth monday in a month
  112.     *
  113.     * @access   private
  114.     * @param    int $month      month
  115.     * @param    int $position   position
  116.     * @return   object Date date
  117.     */
  118.     function _calcNthMondayInMonth($month$position{
  119.         if ($position  ==1{
  120.           $startday='01';
  121.         elseif ($position==2{
  122.           $startday='08';
  123.         elseif ($position==3{
  124.           $startday='15';
  125.         elseif ($position==4{
  126.           $startday='22';
  127.         elseif ($position==5{
  128.           $startday='29';
  129.         }
  130.         $month=sprintf("%02d",$month);
  131.  
  132.         $date   = new Date($this->_year . '-' $month '-' $startday);
  133.         while ($date->getDayOfWeek(!= 1{
  134.             $date  $date->getNextDay();
  135.         }
  136.         return $date;
  137.     }
  138.  
  139.    /**
  140.     * Calculate Nth thursday in a month
  141.     *
  142.     * @access   private
  143.     * @param    int $month      month
  144.     * @param    int $position   position
  145.     * @return   object Date date
  146.     */
  147.     function _calcNthThursdayInMonth($month$position{
  148.         if ($position  ==1{
  149.           $startday='01';
  150.         elseif ($position==2{
  151.           $startday='08';
  152.         elseif ($position==3{
  153.           $startday='15';
  154.         elseif ($position==4{
  155.           $startday='22';
  156.         elseif ($position==5{
  157.           $startday='29';
  158.         }
  159.         $month=sprintf("%02d",$month);
  160.  
  161.         $date   = new Date($this->_year . '-' $month '-' $startday);
  162.         while ($date->getDayOfWeek(!= 4{
  163.             $date  $date->getNextDay();
  164.         }
  165.         return $date;
  166.     }
  167.  
  168.    /**
  169.     * Calculate last monday in a month
  170.     *
  171.     * @access   private
  172.     * @param    int $month  month
  173.     * @return   object Date date
  174.     */
  175.     function _calcLastMondayInMonth($month{
  176.         $month =sprintf("%02d",$month);
  177.         $date   = new Date($this->_year . '-' $month '-01');
  178.         $daysInMonth=$date->getDaysInMonth();
  179.         $date   = new Date($this->_year . '-' $month '-' $daysInMonth );
  180.         while ($date->getDayOfWeek(!= 1{
  181.             $date $date->getPrevDay();
  182.         }
  183.  
  184.         return $date;
  185.     }
  186.  
  187.    /**
  188.     * Calculate nearest workday for a certain day
  189.     *
  190.     * @access   private
  191.     * @param    int $month  month
  192.     * @param    int $day    day
  193.     * @return   object Date date
  194.     */
  195.     function _calcNearestWorkDay($month,$day{
  196.         $month =sprintf("%02d",$month);
  197.         $day  =sprintf("%02d",$day);
  198.       $date   = new Date($this->_year . '-' $month '-' $day);
  199.  
  200.       // When one of these holidays falls on a Saturday, the previous day is also a holiday
  201.       // When New Year's Day, Independence Day, or Christmas Day falls on a Sunday, the next day is also a holiday.
  202.       if ($date->getDayOfWeek(== 0 {
  203.         // bump it up one
  204.          $date   $date->getNextDay();
  205.       }
  206.       if ($date->getDayOfWeek(== 6 {
  207.         // push it back one
  208.          $date   $date->getPrevDay();
  209.       }
  210.  
  211.       return $date;
  212.     }
  213.     
  214.    /**
  215.     * Method that returns an array containing the ISO3166 codes that may possibly
  216.     * identify a driver.
  217.     * 
  218.     * @static
  219.     * @access public
  220.     * @return array possible ISO3166 codes
  221.     */
  222.     function getISO3166Codes({
  223.         return array('us''usa');
  224.     }
  225. }
  226. ?>

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