You are here

public static function PHPExcel_Calculation_DateTime::NETWORKDAYS in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/DateTime.php \PHPExcel_Calculation_DateTime::NETWORKDAYS()

* NETWORKDAYS * * Returns the number of whole working days between start_date and end_date. Working days * exclude weekends and any dates identified in holidays. * Use NETWORKDAYS to calculate employee benefits that accrue based on the number of days * worked during a specific term. * * Excel Function: * NETWORKDAYS(startDate,endDate[,holidays[,holiday[,...]]]) * * @access public * @category Date/Time Functions *

Parameters

mixed $startDate Excel date serial value (float), PHP date timestamp (integer),: * PHP DateTime object, or a standard date string * @param mixed $endDate Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard date string * @param mixed $holidays,... Optional series of Excel date serial value (float), PHP date * timestamp (integer), PHP DateTime object, or a standard date * strings that will be excluded from the working calendar, such * as state and federal holidays and floating holidays. * @return integer Interval between the dates

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/DateTime.php, line 886

Class

PHPExcel_Calculation_DateTime
PHPExcel_Calculation_DateTime

Code

public static function NETWORKDAYS($startDate, $endDate) {

  //	Retrieve the mandatory start and end date that are referenced in the function definition
  $startDate = PHPExcel_Calculation_Functions::flattenSingleValue($startDate);
  $endDate = PHPExcel_Calculation_Functions::flattenSingleValue($endDate);

  //	Flush the mandatory start and end date that are referenced in the function definition, and get the optional days
  $dateArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
  array_shift($dateArgs);
  array_shift($dateArgs);

  //	Validate the start and end dates
  if (is_string($startDate = $sDate = self::_getDateValue($startDate))) {
    return PHPExcel_Calculation_Functions::VALUE();
  }
  $startDate = (double) floor($startDate);
  if (is_string($endDate = $eDate = self::_getDateValue($endDate))) {
    return PHPExcel_Calculation_Functions::VALUE();
  }
  $endDate = (double) floor($endDate);
  if ($sDate > $eDate) {
    $startDate = $eDate;
    $endDate = $sDate;
  }

  // Execute function
  $startDoW = 6 - self::DAYOFWEEK($startDate, 2);
  if ($startDoW < 0) {
    $startDoW = 0;
  }
  $endDoW = self::DAYOFWEEK($endDate, 2);
  if ($endDoW >= 6) {
    $endDoW = 0;
  }
  $wholeWeekDays = floor(($endDate - $startDate) / 7) * 5;
  $partWeekDays = $endDoW + $startDoW;
  if ($partWeekDays > 5) {
    $partWeekDays -= 5;
  }

  //	Test any extra holiday parameters
  $holidayCountedArray = array();
  foreach ($dateArgs as $holidayDate) {
    if (is_string($holidayDate = self::_getDateValue($holidayDate))) {
      return PHPExcel_Calculation_Functions::VALUE();
    }
    if ($holidayDate >= $startDate && $holidayDate <= $endDate) {
      if (self::DAYOFWEEK($holidayDate, 2) < 6 && !in_array($holidayDate, $holidayCountedArray)) {
        --$partWeekDays;
        $holidayCountedArray[] = $holidayDate;
      }
    }
  }
  if ($sDate > $eDate) {
    return 0 - ($wholeWeekDays + $partWeekDays);
  }
  return $wholeWeekDays + $partWeekDays;
}