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.  * USA.php
  5.  *
  6.  * PHP Version 4
  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   Kevin English <kevin@x5dev.com>
  21.  * @license  http://www.php.net/license/3_01.txt PHP License 3.0.1
  22.  * @version  CVS: $Id: USA.php,v 1.11 2008/03/17 11:37:49 kguest Exp $
  23.  * @link     http://pear.php.net/package/Date_Holidays
  24.  */
  25. //
  26.  
  27.  
  28. /**
  29.  * class that calculates observed U.S. holidays
  30.  *
  31.  * @category   Date
  32.  * @package    Date_Holidays
  33.  * @subpackage Driver
  34.  * @author     Kevin English <kevin@x5dev.com>
  35.  * @license    http://www.php.net/license/3_01.txt PHP License 3.0.1
  36.  * @version    CVS: $Id: USA.php,v 1.11 2008/03/17 11:37:49 kguest Exp $
  37.  * @link       http://pear.php.net/package/Date_Holidays
  38.  */
  39. {
  40.     /**
  41.      * Constructor
  42.      *
  43.      * Use the Date_Holidays::factory() method to construct an object of a
  44.      * certain driver
  45.      *
  46.      * @access   protected
  47.      */
  48.     function Date_Holidays_Driver_USA()
  49.     {
  50.     }
  51.  
  52.     /**
  53.      * Build the internal arrays that contain data about the calculated holidays
  54.      *
  55.      * @access   protected
  56.      * @return   boolean true on success, otherwise a PEAR_ErrorStack object
  57.      * @throws   object PEAR_ErrorStack
  58.      */
  59.     function _buildHolidays()
  60.     {
  61.         /**
  62.          * New Year's Day
  63.          */
  64.         $newYearsDay $this->_calcNearestWorkDay('01''01');
  65.         $this->_addHoliday('newYearsDay'$newYearsDay'New Year\'s Day');
  66.  
  67.         $thirdMondayInJanuaryDate $this->_calcNthMondayInMonth(13);
  68.         $this->_addHoliday('mlkDay',
  69.                            $thirdMondayInJanuaryDate,
  70.                            'Dr. Martin Luther King Jr\'s Birthday');
  71.  
  72.         /**
  73.          * President's Day
  74.          */
  75.         $thirdMondayInFebruaryDate $this->_calcNthMondayInMonth(23);
  76.         $this->_addHoliday('presidentsDay',
  77.                            $thirdMondayInFebruaryDate,
  78.                            'President\'s Day');
  79.  
  80.         /**
  81.          * Memorial Day
  82.          */
  83.         $lastMondayInMayDate $this->_calcLastMondayInMonth(5);
  84.         $this->_addHoliday('memorialDay'$lastMondayInMayDate'Memorial Day');
  85.  
  86.         /**
  87.          * 4th of July
  88.          */
  89.         $independenceDay $this->_calcNearestWorkDay('07''04');
  90.         $this->_addHoliday('independenceDay'$independenceDay'Independence Day');
  91.  
  92.         /**
  93.          * Labor Day
  94.          */
  95.         $laborDay $this->_calcNthMondayInMonth(91);
  96.         $this->_addHoliday('laborDay'$laborDay'Labor Day');
  97.  
  98.         /**
  99.          * Columbus Day
  100.          */
  101.         $columbusDay $this->_calcNthMondayInMonth(102);
  102.         $this->_addHoliday('columbusDay'$columbusDay'Columbus Day');
  103.  
  104.         /**
  105.          * Veteran's  Day
  106.          */
  107.         $this->_addHoliday('veteransDay'$this->_year.'-11-11''Veteran\'s Day');
  108.  
  109.         /**
  110.          * Thanksgiving  Day
  111.          */
  112.         $tday $this->_calcNthThursdayInMonth(114);
  113.         $this->_addHoliday('thanksgivingDay'$tday'Thanksgiving Day');
  114.  
  115.         /**
  116.          * Christmas  Day
  117.          */
  118.         $cday $this->_calcNearestWorkDay('12''25');
  119.         $this->_addHoliday('christmasDay'$cday'Christmas Day');
  120.  
  121.         return true;
  122.     }
  123.  
  124.     /**
  125.      * Calculate Nth monday in a month
  126.      *
  127.      * @param int $month    month
  128.      * @param int $position position
  129.      *
  130.      * @access   private
  131.      * @return   object Date date
  132.      */
  133.     function _calcNthMondayInMonth($month$position)
  134.     {
  135.         if ($position  == 1{
  136.             $startday '01';
  137.         elseif ($position == 2{
  138.             $startday '08';
  139.         elseif ($position == 3{
  140.             $startday '15';
  141.         elseif ($position == 4{
  142.             $startday '22';
  143.         elseif ($position == 5{
  144.             $startday '29';
  145.         }
  146.         $month sprintf("%02d"$month);
  147.  
  148.         $date = new Date($this->_year . '-' $month '-' $startday);
  149.         while ($date->getDayOfWeek(!= 1{
  150.             $date $date->getNextDay();
  151.         }
  152.         return $date;
  153.     }
  154.  
  155.     /**
  156.      * Calculate Nth thursday in a month
  157.      *
  158.      * @param int $month    month
  159.      * @param int $position position
  160.      *
  161.      * @access   private
  162.      * @return   object Date date
  163.      */
  164.     function _calcNthThursdayInMonth($month$position)
  165.     {
  166.         if ($position  == 1{
  167.             $startday '01';
  168.         elseif ($position == 2{
  169.             $startday '08';
  170.         elseif ($position == 3{
  171.             $startday '15';
  172.         elseif ($position == 4{
  173.             $startday '22';
  174.         elseif ($position == 5{
  175.             $startday '29';
  176.         }
  177.         $month sprintf("%02d"$month);
  178.  
  179.         $date = new Date($this->_year . '-' $month '-' $startday);
  180.         while ($date->getDayOfWeek(!= 4{
  181.             $date $date->getNextDay();
  182.         }
  183.         return $date;
  184.     }
  185.  
  186.     /**
  187.      * Calculate last monday in a month
  188.      *
  189.      * @param int $month month
  190.      *
  191.      * @access   private
  192.      * @return   object Date date
  193.      */
  194.     function _calcLastMondayInMonth($month)
  195.     {
  196.         $month       sprintf("%02d"$month);
  197.         $date        = new Date($this->_year . '-' $month '-01');
  198.         $daysInMonth $date->getDaysInMonth();
  199.         $date        = new Date($this->_year . '-' $month '-' $daysInMonth);
  200.         while ($date->getDayOfWeek(!= 1{
  201.             $date $date->getPrevDay();
  202.         }
  203.  
  204.         return $date;
  205.     }
  206.  
  207.     /**
  208.      * Calculate nearest workday for a certain day
  209.      *
  210.      * @param int $month month
  211.      * @param int $day   day
  212.      *
  213.      * @access   private
  214.      * @return   object Date date
  215.      */
  216.     function _calcNearestWorkDay($month$day)
  217.     {
  218.         $month sprintf("%02d"$month);
  219.         $day   sprintf("%02d"$day);
  220.         $date  = new Date($this->_year . '-' $month '-' $day);
  221.  
  222.         // When one of these holidays falls on a Saturday, the previous day is
  223.         // also a holiday
  224.         // When New Year's Day, Independence Day, or Christmas Day falls on a
  225.         // Sunday, the next day is also a holiday.
  226.         if ($date->getDayOfWeek(== 0 {
  227.             // bump it up one
  228.             $date $date->getNextDay();
  229.         }
  230.         if ($date->getDayOfWeek(== 6 {
  231.             // push it back one
  232.             $date $date->getPrevDay();
  233.         }
  234.  
  235.         return $date;
  236.     }
  237.  
  238.     /**
  239.      * Method that returns an array containing the ISO3166 codes that may possibly
  240.      * identify a driver.
  241.      *
  242.      * @static
  243.      * @access public
  244.      * @return array possible ISO3166 codes
  245.      */
  246.     function getISO3166Codes()
  247.     {
  248.         return array('us''usa');
  249.     }
  250. }
  251. ?>

Documentation generated on Thu, 10 Apr 2008 20:00:27 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.