開発メモ

開発用のメモです。

PHP n日後が休日の場合は日付を変更する。 (2)

長かったので簡略化してみた。 それでも長いかも

<?php
while( true ) {
    $temporary_expired_date = strtotime( '+' . $addDay . ' day' );
    $arrHoliday = array(
    // @formatter:off 
        # 土曜日
        "6",
        # 日曜日
        "0",
        # 年始
        "1-1", "1-2", "1-3", 
        # 成人の日
        "1-8-1", "1-9-1", "1-10-1", "1-11-1", "1-12-1", "1-13-1", "1-14-1", 
        # 建国記念日
        "2-11", "2-12-1",
        # 昭和の日
        "4-29","4-30-1",
        # ゴールデンウィーク
        "5-3","5-4","5-5","5-6-1","5-6-2","5-6-3",
        # 海の日
        "7-15-1","7-16-1","7-17-1","7-18-1","7-19-1","7-20-1","7-21-1", 
        # 敬老の日
        "9-15-1","9-16-1","9-17-1","9-18-1","9-19-1","9-20-1","9-21-1" ,
        # 体育の日
        "10-8-1", "10-9-1", "10-10-1", "10-11-1", "10-12-1", "10-13-1", "10-14-1",
        # 文化の日
        "11-3","11-4-1",
        # 勤労感謝の日
        "11-23","11-24-1",
        # 昭和の日
        "12-23","12-24-1",
        # 年末
        "12-30","12-31"
    // @formatter:on
    );

    foreach( range(date("Y"), date("Y")+1,1) as $year ) {
        if( $year > 2015 ) {
            # 山の日
            $arrHoliday[ ] = $year . "-8-11";
            $arrHoliday[ ] = $year . "-8-12-1";
        }
        switch($year%4) {
            case 0 :
                # 春分の日
                $arrHoliday[ ] = $year . "-3-20";
                $arrHoliday[ ] = $year . "-3-21-1";
                # 秋分の日
                $arrHoliday[ ] = $year . "-9-22";
                $arrHoliday[ ] = $year . "-9-23-1";
                break;
            case 1 :
            case 2 :
                # 春分の日
                $arrHoliday[ ] = $year . "-3-20";
                $arrHoliday[ ] = $year . "-3-21-1";
                # 秋分の日
                $arrHoliday[ ] = $year . "-9-23";
                $arrHoliday[ ] = $year . "-9-24-1";
                break;
            case 3 :
                # 春分の日
                $arrHoliday[ ] = $year . "-3-21";
                $arrHoliday[ ] = $year . "-3-22-1";
                # 秋分の日
                $arrHoliday[ ] = $year . "-9-23";
                $arrHoliday[ ] = $year . "-9-24-1";
                break;
        }
    }

    if( in_array( date( "w", $temporary_expired_date ), $arrHoliday ) ) {
        $addDay ++ ;
        continue;
    } else if( in_array( date( "n-j", $temporary_expired_date ), $arrHoliday ) ) {
        $addDay ++ ;
        continue;
    } else if( in_array( date( "n-j-w", $temporary_expired_date ), $arrHoliday ) ) {
        $addDay ++ ;
        continue;
    } else if( in_array( date( "Y-n-j", $temporary_expired_date ), $arrHoliday ) ) {
        $addDay ++ ;
        continue;
    } else if( in_array( date( "Y-n-j-w", $temporary_expired_date ), $arrHoliday ) ) {
        $addDay ++ ;
        continue;
    }
    break;
}
Twitter: @asahina_alice