note 56127 deleted from function.strtotime by derick
| From: | derick@php.net | Date: | Sun, 15 Jul 2007 12:46:26 +0000 |
| Subject: | note 56127 deleted from function.strtotime by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-128574@lists.php.net to get a copy of this message | ||
Note Submitter: codepanda at yahoo dot com
----
Building on OJW's comment concerning "stacking" the strtotime function to produce
some quite useful results, I wrote this function to calculate the dates of various holidays commonly
recognized in the US... it may not be elegant, there may be a better way, but it gets the job done
this was tested on PHP 4.4.0; federally recognized holidays were checked against the list located at
http://www.opm.gov/fedhol (covers years 1997-2010, in case
the link goes bad), Mardi Gras was checked for years 2003-2024 as found at http://www.mardigrasdigest.com/html/Mardi_Gras_future_dates_100.htm
<?
/* Function : getHolidays()
** Parameters :
** $year -- the year in question
** Return : an associative array containing the holidays occuring in the given year
** they key is a date stamp of the form Y-m-d, the value is the name of the corresponding
holiday
*/
function getHolidays( $year ) {
$return = array();
// First off, the simple ones
$return[$year . '-01-01'] = 'New Year`s Day';
$return[$year . '-02-14'] = 'Valentine`s Day';
$return[$year . '-06-14'] = 'Flag Day';
$return[$year . '-07-04'] = 'Independence Day';
$return[$year . '-11-11'] = 'Veteran`s Day';
$return[$year . '-12-25'] = 'Christmas';
// and now, the more complex ones
// Martin Luther King, Jr. Day
// third Monday in January
$return[date( 'Y-m-d', strtotime( '2 weeks monday', strtotime( "January 1,
$year" ) ) + 43200 )] = 'Martin Luther King, Jr. Day';
// Presidents` Day
// third Monday in February
$return[date( 'Y-m-d', strtotime( '2 weeks monday', strtotime( "February
1, $year" ) ) + 43200 )] = 'Presidents` Day';
// Mardi Gras
// Tuesday ~47 days before Easter
$return[date( 'Y-m-d', strtotime( 'last tuesday 46 days ago', easter_date(
$year ) ) + 43200 )] = 'Mardi Gras';
// Easter
// the Sunday after the first full moon which falls on or after the Spring Equinox
// thank god PHP has a function for that...
$return[date( 'Y-m-d', easter_date( $year ) + 43200 )] = 'Easter';
// Memorial Day
// last Monday in May
$return[date( 'Y-m-d', strtotime( '-1 week monday', strtotime( "June 1,
$year" ) ) + 43200 )] = 'Memorial Day';
// Labor Day
// first Monday in September
$return[date( 'Y-m-d', strtotime( 'monday', strtotime( "September 1,
$year" ) ) + 43200 )] = 'Labor Day';
// Columbus Day
// second Monday in October
$return[date( 'Y-m-d', strtotime( '1 week monday', strtotime( "October 1,
$year" ) ) + 43200 )] = 'Columbus Day';
// Thanksgiving
// fourth Thursday in November
$return[date( 'Y-m-d', strtotime( '3 weeks thursday', strtotime( "November
1, $year" ) ) + 43200 )] = 'Thanksgiving';
ksort( $return );
return $return;
}
?>