You are here

public static function PHPExcel_Calculation_DateTime::DATEVALUE in Loft Data Grids 7.2

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

* DATEVALUE * * Returns a value that represents a particular date. * Use DATEVALUE to convert a date represented by a text string to an Excel or PHP date/time stamp * value. * * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date * format of your regional settings. PHPExcel does not change cell formatting in this way. * * Excel Function: * DATEVALUE(dateValue) * * @access public * @category Date/Time Functions *

Parameters

string $dateValue Text that represents a date in a Microsoft Excel date format.: * For example, "1/30/2008" or "30-Jan-2008" are text strings within * quotation marks that represent dates. Using the default date * system in Excel for Windows, date_text must represent a date from * January 1, 1900, to December 31, 9999. Using the default date * system in Excel for the Macintosh, date_text must represent a date * from January 1, 1904, to December 31, 9999. DATEVALUE returns the * #VALUE! error value if date_text is out of this range. * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag

6 calls to PHPExcel_Calculation_DateTime::DATEVALUE()
DateTimeTest::testDATEVALUEtoPHP in vendor/phpoffice/phpexcel/unitTests/Classes/PHPExcel/Calculation/DateTimeTest.php
DateTimeTest::testDATEVALUEtoPHPObject in vendor/phpoffice/phpexcel/unitTests/Classes/PHPExcel/Calculation/DateTimeTest.php
PHPExcel_Calculation_DateTime::_getDateValue in vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/DateTime.php
* _getDateValue * *
PHPExcel_Calculation_TextData::TEXTFORMAT in vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/TextData.php
* TEXTFORMAT * *
PHPExcel_Calculation_TextData::VALUE in vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/TextData.php
* VALUE * *

... See full list

File

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

Class

PHPExcel_Calculation_DateTime
PHPExcel_Calculation_DateTime

Code

public static function DATEVALUE($dateValue = 1) {
  $dateValue = trim(PHPExcel_Calculation_Functions::flattenSingleValue($dateValue), '"');

  //	Strip any ordinals because they're allowed in Excel (English only)
  $dateValue = preg_replace('/(\\d)(st|nd|rd|th)([ -\\/])/Ui', '$1$3', $dateValue);

  //	Convert separators (/ . or space) to hyphens (should also handle dot used for ordinals in some countries, e.g. Denmark, Germany)
  $dateValue = str_replace(array(
    '/',
    '.',
    '-',
    '  ',
  ), array(
    ' ',
    ' ',
    ' ',
    ' ',
  ), $dateValue);
  $yearFound = false;
  $t1 = explode(' ', $dateValue);
  foreach ($t1 as &$t) {
    if (is_numeric($t) && $t > 31) {
      if ($yearFound) {
        return PHPExcel_Calculation_Functions::VALUE();
      }
      else {
        if ($t < 100) {
          $t += 1900;
        }
        $yearFound = true;
      }
    }
  }
  if (count($t1) == 1 && strpos($t, ':') != false) {

    //	We've been fed a time value without any date
    return 0.0;
  }
  elseif (count($t1) == 2) {

    //	We only have two parts of the date: either day/month or month/year
    if ($yearFound) {
      array_unshift($t1, 1);
    }
    else {
      array_push($t1, date('Y'));
    }
  }
  unset($t);
  $dateValue = implode(' ', $t1);
  $PHPDateArray = date_parse($dateValue);
  if ($PHPDateArray === False || $PHPDateArray['error_count'] > 0) {
    $testVal1 = strtok($dateValue, '- ');
    if ($testVal1 !== False) {
      $testVal2 = strtok('- ');
      if ($testVal2 !== False) {
        $testVal3 = strtok('- ');
        if ($testVal3 === False) {
          $testVal3 = strftime('%Y');
        }
      }
      else {
        return PHPExcel_Calculation_Functions::VALUE();
      }
    }
    else {
      return PHPExcel_Calculation_Functions::VALUE();
    }
    $PHPDateArray = date_parse($testVal1 . '-' . $testVal2 . '-' . $testVal3);
    if ($PHPDateArray === False || $PHPDateArray['error_count'] > 0) {
      $PHPDateArray = date_parse($testVal2 . '-' . $testVal1 . '-' . $testVal3);
      if ($PHPDateArray === False || $PHPDateArray['error_count'] > 0) {
        return PHPExcel_Calculation_Functions::VALUE();
      }
    }
  }
  if ($PHPDateArray !== False && $PHPDateArray['error_count'] == 0) {

    // Execute function
    if ($PHPDateArray['year'] == '') {
      $PHPDateArray['year'] = strftime('%Y');
    }
    if ($PHPDateArray['year'] < 1900) {
      return PHPExcel_Calculation_Functions::VALUE();
    }
    if ($PHPDateArray['month'] == '') {
      $PHPDateArray['month'] = strftime('%m');
    }
    if ($PHPDateArray['day'] == '') {
      $PHPDateArray['day'] = strftime('%d');
    }
    $excelDateValue = floor(PHPExcel_Shared_Date::FormattedPHPToExcel($PHPDateArray['year'], $PHPDateArray['month'], $PHPDateArray['day'], $PHPDateArray['hour'], $PHPDateArray['minute'], $PHPDateArray['second']));
    switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
      case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL:
        return (double) $excelDateValue;
      case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC:
        return (int) PHPExcel_Shared_Date::ExcelToPHP($excelDateValue);
      case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT:
        return new DateTime($PHPDateArray['year'] . '-' . $PHPDateArray['month'] . '-' . $PHPDateArray['day'] . ' 00:00:00');
    }
  }
  return PHPExcel_Calculation_Functions::VALUE();
}