Uzyskaj dni nieobecne w dniach roboczych od danego zakresu daty


<?php

$imaginaryWorkDatesOfWorker1 = array(
    '01-02-2012', '02-02-2012', '03-02-2012', '06-02-2012', '07-02-2012', '08-02-2012',
    '09-02-2012', '14-02-2012', '15-02-2012', '16-02-2012', '17-02-2012', '20-02-2012',
    '21-02-2012', '22-02-2012', '27-02-2012', '28-02-2012', '29-02-2012'    
);

$leaveDays1 = getLeaveDays(2, 2012, $imaginaryWorkDatesOfWorker1);
displayWorkersLeaveDays($leaveDays1);



function getLeaveDays($month, $year, $arrDatesPresent=array()){
  $arrAllWorkDatesInMonth = getDatesInTheMonth($month, $year);

  $leaveDays = array_diff($arrAllWorkDatesInMonth, $arrDatesPresent);
  return $leaveDays;
}


function getDatesInTheMonth($month, $year, $includeWeekends=false, $format2Use='d-m-Y')    {
  $arrDatesInTheMonth = array();
  if (empty($format2Use)) $format2Use = 'm-d-Y';

  if (empty($month) || empty($year)){
    throw new Exception("Invalid parameters given.");
  }
  else{
    $fauxDate = mktime(0, 0, 0, $month, 1, $year);
    $numOfDaysInMonth = date('t', $fauxDate);

    if (!empty($numOfDaysInMonth)){
        for ($day = 1; $day <= $numOfDaysInMonth; $day++){

            $timeStamp = mktime(0, 0, 0, $month, $day, $year);
            $cdate = date($format2Use, $timeStamp);

            if ($includeWeekends){
                $arrDatesInTheMonth[] = $cdate;
            }
            else{
                if (!isWeekend($cdate)) { $arrDatesInTheMonth[] = $cdate; }
            }
        }
    }
  }

  return $arrDatesInTheMonth;
}

function isWeekend($date) {
  return (date('N', strtotime($date)) >= 7);
}


function isWeekend2($date) {
  $weekDay = date('w', strtotime($date));
  return ($weekDay == 0 || $weekDay == 6);
}

function printDates($arrDates){
  foreach ($arrDates as $key => $cdate) {
      $display = sprintf( '%s <br />', date('[l] - jS \of F Y', strtotime($cdate)) );
      echo $display;
  }
}

function displayWorkersLeaveDays($leaveDays){
  echo '<div style="background-color:#CCC;margin:10px 0;">';
  echo '<div>Your Leave days are as follows: </div>';
  printDates($leaveDays);
  echo '</div>';
}
?>
faheem