Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help with US Holidays

0 views
Skip to first unread message

News

unread,
Mar 10, 2004, 7:48:55 PM3/10/04
to
All,
These are some functions I am using to calculate holidays, however,
Grandparents Day seems to be giving me some trouble.
This is what I am using to determine Labor Day (since GP day is the Sunday
after):

echo "Labor Day Observed (First Monday in September) = " . get_holiday( $y,
9, 1, 1 );
//Grandparents' Day, Sunday after Labor Day
echo "Grandparents' Day (Sunday after Labor Day) = " . get_holiday( ?, ?, ?,
? );

Using these functions, is it possible to determine GP day ?

function format_date( $year, $month, $day )
{
if ( strlen( $month ) == 1 ) {
$month = "0" . $month;
}
if ( strlen( $day ) == 1 ) {
$day = "0" . $day;
}
// $date = $year . "-" . $month . "-" . $day; //YYYY-MM-DD
$date = $month . "-" . $day . "-" . $year; //MM-DD-YYYY

return $date;
}

function get_holiday( $year, $month, $day_of_week, $week = "" )
{
if ( ( ( $week != "" ) && ( ( $week > 5 ) || ( $week < 1 ) ) ) || (
$day_of_week > 6 ) || ( $day_of_week < 0 ) ) {
// $day_of_week must be between 0 and 6 (Sun=0, ... Sat=6); $week must be
between 1 and 5
return false;
} else {
if ( !$week || ( $week == "" ) ) {
$lastday = date( "t", mktime( 0, 0, 0, $month, 1, $year ) );
$temp = ( date( "w", mktime( 0, 0, 0, $month, $lastday, $year ) ) -
$day_of_week ) % 7;
} else {
$temp = ( $day_of_week - date( "w", mktime( 0, 0, 0, $month, 1,
$year ) ) ) % 7;
}

if ( $temp < 0 ) {
$temp += 7;
}

if ( !$week || ( $week == "" ) ) {
$day = $lastday - $temp;
} else {
$day = ( 7 * $week ) - 6 + $temp;
}

return format_date( $year, $month, $day );
}
}


Jochen Daum

unread,
Mar 10, 2004, 8:21:31 PM3/10/04
to
Hi News,

On Wed, 10 Mar 2004 15:48:55 -0900, "News" <ne...@news.com> wrote:

>All,
>These are some functions I am using to calculate holidays, however,
>Grandparents Day seems to be giving me some trouble.
>This is what I am using to determine Labor Day (since GP day is the Sunday
>after):
>
>echo "Labor Day Observed (First Monday in September) = " . get_holiday( $y,
>9, 1, 1 );
>//Grandparents' Day, Sunday after Labor Day
>echo "Grandparents' Day (Sunday after Labor Day) = " . get_holiday( ?, ?, ?,
>? );
>
>Using these functions, is it possible to determine GP day ?
>

If you have a database handy,

make an Excel sheet with all days for the next 10 years and fill in
the LAbour Days into a column as 1. You can then much more easily find
out what 'fetaures' a day has, and its easy to debug.

HTH, Jochen
--
Jochen Daum - Cabletalk Group Ltd.
PHP DB Edit Toolkit -- PHP scripts for building
database editing interfaces.
http://sourceforge.net/projects/phpdbedittk/

StinkFinger

unread,
Mar 10, 2004, 11:37:52 PM3/10/04
to
echo "<li>Labor Day Observed (First Monday in September) = " .

get_holiday( $y, 9, 1, 1 );
//Grandparents' Day, Sunday after Labor Day
$lbday = get_holiday( $y, 9, 1, 1 ); //09-06-2004
list($lmonth,$lday,$lyear) = explode("-",$lbday);
$gptimestamp = mktime(0, 0, 0, $lmonth, $lday + 6, $lyear);
$gpday = date("m-d-Y", $gptimestamp);
echo "<li>Grandparents' Day (Sunday after Labor Day) = " . $gpday;

"News" <ne...@news.com> wrote in message
news:104vdrp...@corp.supernews.com...

0 new messages