Source for file USA.php
Documentation is available at USA.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
* Copyright (c) 1997-2008 The PHP Group
* This source file is subject to version 3.0 of the PHP license,
* that is bundled with this package in the file LICENSE, and is
* available at through the world-wide-web at
* http://www.php.net/license/3_01.txt.
* If you did not receive a copy of the PHP license and are unable to
* obtain it through the world-wide-web, please send a note to
* license@php.net so we can mail you a copy immediately.
* @author Kevin English <kevin@x5dev.com>
* @license http://www.php.net/license/3_01.txt PHP License 3.0.1
* @version CVS: $Id: USA.php,v 1.11 2008/03/17 11:37:49 kguest Exp $
* @link http://pear.php.net/package/Date_Holidays
* class that calculates observed U.S. holidays
* @author Kevin English <kevin@x5dev.com>
* @license http://www.php.net/license/3_01.txt PHP License 3.0.1
* @version CVS: $Id: USA.php,v 1.11 2008/03/17 11:37:49 kguest Exp $
* @link http://pear.php.net/package/Date_Holidays
* Use the Date_Holidays::factory() method to construct an object of a
* Build the internal arrays that contain data about the calculated holidays
* @return boolean true on success, otherwise a PEAR_ErrorStack object
* @throws object PEAR_ErrorStack
$newYearsDay = $this->_calcNearestWorkDay ('01', '01');
$this->_addHoliday('newYearsDay', $newYearsDay, 'New Year\'s Day');
$thirdMondayInJanuaryDate = $this->_calcNthMondayInMonth (1 , 3 );
$thirdMondayInJanuaryDate,
'Dr. Martin Luther King Jr\'s Birthday');
$thirdMondayInFebruaryDate = $this->_calcNthMondayInMonth (2 , 3 );
$thirdMondayInFebruaryDate,
$lastMondayInMayDate = $this->_calcLastMondayInMonth (5 );
$this->_addHoliday('memorialDay', $lastMondayInMayDate, 'Memorial Day');
$independenceDay = $this->_calcNearestWorkDay ('07', '04');
$this->_addHoliday('independenceDay', $independenceDay, 'Independence Day');
$laborDay = $this->_calcNthMondayInMonth (9 , 1 );
$this->_addHoliday('laborDay', $laborDay, 'Labor Day');
$columbusDay = $this->_calcNthMondayInMonth (10 , 2 );
$this->_addHoliday('columbusDay', $columbusDay, 'Columbus Day');
$tday = $this->_calcNthThursdayInMonth (11 , 4 );
$this->_addHoliday('thanksgivingDay', $tday, 'Thanksgiving Day');
$cday = $this->_calcNearestWorkDay ('12', '25');
$this->_addHoliday('christmasDay', $cday, 'Christmas Day');
* Calculate Nth monday in a month
* @param int $month month
* @param int $position position
* @return object Date date
function _calcNthMondayInMonth ($month, $position)
} elseif ($position == 2 ) {
} elseif ($position == 3 ) {
} elseif ($position == 4 ) {
} elseif ($position == 5 ) {
$date = new Date ($this->_year . '-' . $month . '-' . $startday);
while ($date->getDayOfWeek () != 1 ) {
$date = $date->getNextDay ();
* Calculate Nth thursday in a month
* @param int $month month
* @param int $position position
* @return object Date date
function _calcNthThursdayInMonth ($month, $position)
} elseif ($position == 2 ) {
} elseif ($position == 3 ) {
} elseif ($position == 4 ) {
} elseif ($position == 5 ) {
$date = new Date ($this->_year . '-' . $month . '-' . $startday);
while ($date->getDayOfWeek () != 4 ) {
$date = $date->getNextDay ();
* Calculate last monday in a month
* @param int $month month
* @return object Date date
function _calcLastMondayInMonth ($month)
$date = new Date ($this->_year . '-' . $month . '-01');
$daysInMonth = $date->getDaysInMonth ();
$date = new Date ($this->_year . '-' . $month . '-' . $daysInMonth);
while ($date->getDayOfWeek () != 1 ) {
$date = $date->getPrevDay ();
* Calculate nearest workday for a certain day
* @param int $month month
* @return object Date date
function _calcNearestWorkDay ($month, $day)
$date = new Date ($this->_year . '-' . $month . '-' . $day);
// When one of these holidays falls on a Saturday, the previous day is
// When New Year's Day, Independence Day, or Christmas Day falls on a
// Sunday, the next day is also a holiday.
if ($date->getDayOfWeek () == 0 ) {
$date = $date->getNextDay ();
if ($date->getDayOfWeek () == 6 ) {
$date = $date->getPrevDay ();
* Method that returns an array containing the ISO3166 codes that may possibly
* @return array possible ISO3166 codes
return array ('us', 'usa');
Documentation generated on Thu, 10 Apr 2008 20:00:27 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.
|