You are here

public static function PHPExcel_Calculation_DateTime::WEEKOFYEAR 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::WEEKOFYEAR()

* WEEKOFYEAR * * Returns the week of the year for a specified date. * The WEEKNUM function considers the week containing January 1 to be the first week of the year. * However, there is a European standard that defines the first week as the one with the majority * of days (four or more) falling in the new year. This means that for years in which there are * three days or less in the first week of January, the WEEKNUM function returns week numbers * that are incorrect according to the European standard. * * Excel Function: * WEEKNUM(dateValue[,style]) * *

Parameters

mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),: * PHP DateTime object, or a standard date string * @param boolean $method Week begins on Sunday or Monday * 1 or omitted Week begins on Sunday. * 2 Week begins on Monday. * @return int Week Number

File

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

Class

PHPExcel_Calculation_DateTime
PHPExcel_Calculation_DateTime

Code

public static function WEEKOFYEAR($dateValue = 1, $method = 1) {
  $dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue);
  $method = PHPExcel_Calculation_Functions::flattenSingleValue($method);
  if (!is_numeric($method)) {
    return PHPExcel_Calculation_Functions::VALUE();
  }
  elseif ($method < 1 || $method > 2) {
    return PHPExcel_Calculation_Functions::NaN();
  }
  $method = floor($method);
  if ($dateValue === null) {
    $dateValue = 1;
  }
  elseif (is_string($dateValue = self::_getDateValue($dateValue))) {
    return PHPExcel_Calculation_Functions::VALUE();
  }
  elseif ($dateValue < 0.0) {
    return PHPExcel_Calculation_Functions::NaN();
  }

  // Execute function
  $PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($dateValue);
  $dayOfYear = $PHPDateObject
    ->format('z');
  $dow = $PHPDateObject
    ->format('w');
  $PHPDateObject
    ->modify('-' . $dayOfYear . ' days');
  $dow = $PHPDateObject
    ->format('w');
  $daysInFirstWeek = 7 - ($dow + (2 - $method)) % 7;
  $dayOfYear -= $daysInFirstWeek;
  $weekOfYear = ceil($dayOfYear / 7) + 1;
  return (int) $weekOfYear;
}