I am trying to create a recursive function which calculates gift delivery dates according to some predefined rules which are:
- A gift can be delivered after one day of booking
- If booked on Saturday or Sunday then the gift will be delivered after the next working day + one processing day.
- The resulting date might not be in predefined holidays.
I have created the following function, but it’s returning me incorrect date.
// The delivery date might not be from these dates
$holidays_selected = array('23-10-2015', '24-10-2015', '28-10-2015');
echo $gift_delivery_date = getGiftDeliveryDate(date('d-m-Y', strtotime('+1 Day')), $holidays_selected);
// It prints 25-10-2015 what i expect is 27-10-2015
function getGiftDeliveryDate($asuumed_date, $holidays) {
    $tomorrow = '';
    if (in_array($asuumed_date, $holidays)) {
        $tomorrow = date('d-m-Y', strtotime($asuumed_date . '+1 Day'));
        getGiftDeliveryDate($tomorrow, $holidays);
    } else if (date('N', strtotime($asuumed_date)) == 6) {
        $tomorrow = date('d-m-Y', strtotime($asuumed_date . '+3 Day'));
        if(in_array($tomorrow, $holidays)) {
            $tomorrow = date('d-m-Y', strtotime($tomorrow . '+1 Day'));
            getGiftDeliveryDate($tomorrow, $holidays);
        }
    } else if (date('N', strtotime($asuumed_date)) == 7) {
        $tomorrow = date('d-m-Y', strtotime($asuumed_date . '+2 Day'));
        if(in_array($tomorrow, $holidays)) {
            $tomorrow = date('d-m-Y', strtotime($tomorrow . '+1 Day'));
            getGiftDeliveryDate($tomorrow, $holidays);
        }
    } else {
        $tomorrow = $asuumed_date;
    }
    return $tomorrow;
}
I expect 27-10-2015 as the output, but it is giving 25-10-2015 as the final output.
 
     
    