note 56127 added to function.strtotime

From: Date: Wed, 24 Aug 2005 11:29:33 +0000
Subject: note 56127 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-94122@lists.php.net to get a copy of this message
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; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.strtotime.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+56127 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56127&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56127&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56127&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56127&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56127&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56127&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+56127&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#94122) next »