Help with US Holidays

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • News

    Help with US Holidays

    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 "Grandparen ts' 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

    #2
    Re: Help with US Holidays

    Hi News,

    On Wed, 10 Mar 2004 15:48:55 -0900, "News" <news@news.co m> wrote:
    [color=blue]
    >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 "Grandparen ts' Day (Sunday after Labor Day) = " . get_holiday( ?, ?, ?,
    >? );
    >
    >Using these functions, is it possible to determine GP day ?
    >[/color]
    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.
    Download PHP DB Edit Toolkit for free. PHP DB Edit Toolkit is a set of PHP classes makes the generation of database edit interfaces easier and faster. The main class builds tabular and form views based on a data dictionary and takes over handling of insert/update/delete and user input.

    Comment

    • StinkFinger

      #3
      Re: Help with US Holidays

      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,$l day,$lyear) = explode("-",$lbday);
      $gptimestamp = mktime(0, 0, 0, $lmonth, $lday + 6, $lyear);
      $gpday = date("m-d-Y", $gptimestamp);
      echo "<li>Grandparen ts' Day (Sunday after Labor Day) = " . $gpday;

      "News" <news@news.co m> wrote in message
      news:104vdrpep8 8eh6e@corp.supe rnews.com...[color=blue]
      > 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([/color]
      $y,[color=blue]
      > 9, 1, 1 );
      > //Grandparents' Day, Sunday after Labor Day
      > echo "Grandparen ts' Day (Sunday after Labor Day) = " . get_holiday( ?, ?,[/color]
      ?,[color=blue]
      > ? );
      >
      > 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[/color]
      be[color=blue]
      > 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 );
      > }
      > }
      >
      >[/color]


      Comment

      Working...