Calculate business days

后端 未结 30 1851
猫巷女王i
猫巷女王i 2020-11-22 05:16

I need a method for adding \"business days\" in PHP. For example, Friday 12/5 + 3 business days = Wednesday 12/10.

At a minimum I need the code to understand weekend

30条回答
  •  长发绾君心
    2020-11-22 06:01

    Holiday calculation is non-standard in each State. I am writing a bank application which I need some hard business rules for but can still only get a rough standard.

    /**
     * National American Holidays
     * @param string $year
     * @return array
     */
    public static function getNationalAmericanHolidays($year) {
    
    
        //  January 1 - New Year’s Day (Observed)
        //  Calc Last Monday in May - Memorial Day  strtotime("last Monday of May 2011");
        //  July 4 Independence Day
        //  First monday in september - Labor Day strtotime("first Monday of September 2011")
        //  November 11 - Veterans’ Day (Observed)
        //  Fourth Thursday in November Thanksgiving strtotime("fourth Thursday of November 2011");
        //  December 25 - Christmas Day        
        $bankHolidays = array(
              $year . "-01-01" // New Years
            , "". date("Y-m-d",strtotime("last Monday of May " . $year) ) // Memorial Day
            , $year . "-07-04" // Independence Day (corrected)
            , "". date("Y-m-d",strtotime("first Monday of September " . $year) ) // Labor Day
            , $year . "-11-11" // Veterans Day
            , "". date("Y-m-d",strtotime("fourth Thursday of November " . $year) ) // Thanksgiving
            , $year . "-12-25" // XMAS
            );
    
        return $bankHolidays;
    }
    

提交回复
热议问题