Source for file USA.php
Documentation is available at USA.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.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/2_02.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. |
// +----------------------------------------------------------------------+
// | Authors: Kevin English <kevin@x5dev.com> |
// +----------------------------------------------------------------------+
* class that calculates observed U.S. holidays
* @version $Id: USA.php,v 1.4 2006/04/02 22:19:06 luckec Exp $
* @author Kevin English <kevin@x5dev.com>
* Use the Date_Holidays::factory() method to construct an object of a certain driver
* 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 );
$this->_addHoliday('mlkDay', $thirdMondayInJanuaryDate, 'Dr. Martin Luther King Jr\'s Birthday');
$thirdMondayInFebruaryDate = $this->_calcNthMondayInMonth (2 ,3 );
$this->_addHoliday('presidentsDay', $thirdMondayInFebruaryDate, 'President\'s Day');
$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 );
$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 also a holiday
// 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 Mon, 11 Mar 2019 15:03:09 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|