You are here

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

* TIME * * The TIME function returns a value that represents a particular time. * * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the time * format of your regional settings. PHPExcel does not change cell formatting in this way. * * Excel Function: * TIME(hour,minute,second) * * @access public * @category Date/Time Functions *

Parameters

integer $hour A number from 0 (zero) to 32767 representing the hour.: * Any value greater than 23 will be divided by 24 and the remainder * will be treated as the hour value. For example, TIME(27,0,0) = * TIME(3,0,0) = .125 or 3:00 AM. * @param integer $minute A number from 0 to 32767 representing the minute. * Any value greater than 59 will be converted to hours and minutes. * For example, TIME(0,750,0) = TIME(12,30,0) = .520833 or 12:30 PM. * @param integer $second A number from 0 to 32767 representing the second. * Any value greater than 59 will be converted to hours, minutes, * and seconds. For example, TIME(0,0,2000) = TIME(0,33,22) = .023148 * or 12:33:20 AM * @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

2 calls to PHPExcel_Calculation_DateTime::TIME()
DateTimeTest::testTIMEtoPHP in vendor/phpoffice/phpexcel/unitTests/Classes/PHPExcel/Calculation/DateTimeTest.php
DateTimeTest::testTIMEtoPHPObject in vendor/phpoffice/phpexcel/unitTests/Classes/PHPExcel/Calculation/DateTimeTest.php

File

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

Class

PHPExcel_Calculation_DateTime
PHPExcel_Calculation_DateTime

Code

public static function TIME($hour = 0, $minute = 0, $second = 0) {
  $hour = PHPExcel_Calculation_Functions::flattenSingleValue($hour);
  $minute = PHPExcel_Calculation_Functions::flattenSingleValue($minute);
  $second = PHPExcel_Calculation_Functions::flattenSingleValue($second);
  if ($hour == '') {
    $hour = 0;
  }
  if ($minute == '') {
    $minute = 0;
  }
  if ($second == '') {
    $second = 0;
  }
  if (!is_numeric($hour) || !is_numeric($minute) || !is_numeric($second)) {
    return PHPExcel_Calculation_Functions::VALUE();
  }
  $hour = (int) $hour;
  $minute = (int) $minute;
  $second = (int) $second;
  if ($second < 0) {
    $minute += floor($second / 60);
    $second = 60 - abs($second % 60);
    if ($second == 60) {
      $second = 0;
    }
  }
  elseif ($second >= 60) {
    $minute += floor($second / 60);
    $second = $second % 60;
  }
  if ($minute < 0) {
    $hour += floor($minute / 60);
    $minute = 60 - abs($minute % 60);
    if ($minute == 60) {
      $minute = 0;
    }
  }
  elseif ($minute >= 60) {
    $hour += floor($minute / 60);
    $minute = $minute % 60;
  }
  if ($hour > 23) {
    $hour = $hour % 24;
  }
  elseif ($hour < 0) {
    return PHPExcel_Calculation_Functions::NaN();
  }

  // Execute function
  switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
    case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL:
      $date = 0;
      $calendar = PHPExcel_Shared_Date::getExcelCalendar();
      if ($calendar != PHPExcel_Shared_Date::CALENDAR_WINDOWS_1900) {
        $date = 1;
      }
      return (double) PHPExcel_Shared_Date::FormattedPHPToExcel($calendar, 1, $date, $hour, $minute, $second);
    case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC:
      return (int) PHPExcel_Shared_Date::ExcelToPHP(PHPExcel_Shared_Date::FormattedPHPToExcel(1970, 1, 1, $hour, $minute, $second));

    // -2147468400; //	-2147472000 + 3600
    case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT:
      $dayAdjust = 0;
      if ($hour < 0) {
        $dayAdjust = floor($hour / 24);
        $hour = 24 - abs($hour % 24);
        if ($hour == 24) {
          $hour = 0;
        }
      }
      elseif ($hour >= 24) {
        $dayAdjust = floor($hour / 24);
        $hour = $hour % 24;
      }
      $phpDateObject = new DateTime('1900-01-01 ' . $hour . ':' . $minute . ':' . $second);
      if ($dayAdjust != 0) {
        $phpDateObject
          ->modify($dayAdjust . ' days');
      }
      return $phpDateObject;
  }
}