PageRenderTime 61ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/common/libraries/plugin/phpexcel/PHPExcel/Calculation/DateTime.php

https://bitbucket.org/renaatdemuynck/chamilo
PHP | 1450 lines | 1062 code | 136 blank | 252 comment | 222 complexity | cd33aaaff758c12fa398817018dfbd76 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, LGPL-3.0, GPL-3.0, MIT, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2011 PHPExcel
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPExcel
  22. * @package PHPExcel_Calculation
  23. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version 1.7.6, 2011-02-27
  26. */
  27. /** PHPExcel root directory */
  28. if (! defined('PHPEXCEL_ROOT'))
  29. {
  30. /**
  31. * @ignore
  32. */
  33. define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
  34. require (PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
  35. }
  36. /**
  37. * PHPExcel_Calculation_DateTime
  38. *
  39. * @category PHPExcel
  40. * @package PHPExcel_Calculation
  41. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  42. */
  43. class PHPExcel_Calculation_DateTime
  44. {
  45. public static function _isLeapYear($year)
  46. {
  47. return ((($year % 4) == 0) && (($year % 100) != 0) || (($year % 400) == 0));
  48. } // function _isLeapYear()
  49. private static function _dateDiff360($startDay, $startMonth, $startYear, $endDay, $endMonth, $endYear, $methodUS)
  50. {
  51. if ($startDay == 31)
  52. {
  53. -- $startDay;
  54. }
  55. elseif ($methodUS && ($startMonth == 2 && ($startDay == 29 || ($startDay == 28 && ! self :: _isLeapYear($startYear)))))
  56. {
  57. $startDay = 30;
  58. }
  59. if ($endDay == 31)
  60. {
  61. if ($methodUS && $startDay != 30)
  62. {
  63. $endDay = 1;
  64. if ($endMonth == 12)
  65. {
  66. ++ $endYear;
  67. $endMonth = 1;
  68. }
  69. else
  70. {
  71. ++ $endMonth;
  72. }
  73. }
  74. else
  75. {
  76. $endDay = 30;
  77. }
  78. }
  79. return $endDay + $endMonth * 30 + $endYear * 360 - $startDay - $startMonth * 30 - $startYear * 360;
  80. } // function _dateDiff360()
  81. /**
  82. * _getDateValue
  83. *
  84. * @param string $dateValue
  85. * @return mixed Excel date/time serial value, or string if error
  86. */
  87. public static function _getDateValue($dateValue)
  88. {
  89. if (! is_numeric($dateValue))
  90. {
  91. if ((is_string($dateValue)) && (PHPExcel_Calculation_Functions :: getCompatibilityMode() == PHPExcel_Calculation_Functions :: COMPATIBILITY_GNUMERIC))
  92. {
  93. return PHPExcel_Calculation_Functions :: VALUE();
  94. }
  95. if ((is_object($dateValue)) && ($dateValue instanceof PHPExcel_Shared_Date :: $dateTimeObjectType))
  96. {
  97. $dateValue = PHPExcel_Shared_Date :: PHPToExcel($dateValue);
  98. }
  99. else
  100. {
  101. $saveReturnDateType = PHPExcel_Calculation_Functions :: getReturnDateType();
  102. PHPExcel_Calculation_Functions :: setReturnDateType(PHPExcel_Calculation_Functions :: RETURNDATE_EXCEL);
  103. $dateValue = self :: DATEVALUE($dateValue);
  104. PHPExcel_Calculation_Functions :: setReturnDateType($saveReturnDateType);
  105. }
  106. }
  107. return $dateValue;
  108. } // function _getDateValue()
  109. /**
  110. * _getTimeValue
  111. *
  112. * @param string $timeValue
  113. * @return mixed Excel date/time serial value, or string if error
  114. */
  115. private static function _getTimeValue($timeValue)
  116. {
  117. $saveReturnDateType = PHPExcel_Calculation_Functions :: getReturnDateType();
  118. PHPExcel_Calculation_Functions :: setReturnDateType(PHPExcel_Calculation_Functions :: RETURNDATE_EXCEL);
  119. $timeValue = self :: TIMEVALUE($timeValue);
  120. PHPExcel_Calculation_Functions :: setReturnDateType($saveReturnDateType);
  121. return $timeValue;
  122. } // function _getTimeValue()
  123. private static function _adjustDateByMonths($dateValue = 0, $adjustmentMonths = 0)
  124. {
  125. // Execute function
  126. $PHPDateObject = PHPExcel_Shared_Date :: ExcelToPHPObject($dateValue);
  127. $oMonth = (int) $PHPDateObject->format('m');
  128. $oYear = (int) $PHPDateObject->format('Y');
  129. $adjustmentMonthsString = (string) $adjustmentMonths;
  130. if ($adjustmentMonths > 0)
  131. {
  132. $adjustmentMonthsString = '+' . $adjustmentMonths;
  133. }
  134. if ($adjustmentMonths != 0)
  135. {
  136. $PHPDateObject->modify($adjustmentMonthsString . ' months');
  137. }
  138. $nMonth = (int) $PHPDateObject->format('m');
  139. $nYear = (int) $PHPDateObject->format('Y');
  140. $monthDiff = ($nMonth - $oMonth) + (($nYear - $oYear) * 12);
  141. if ($monthDiff != $adjustmentMonths)
  142. {
  143. $adjustDays = (int) $PHPDateObject->format('d');
  144. $adjustDaysString = '-' . $adjustDays . ' days';
  145. $PHPDateObject->modify($adjustDaysString);
  146. }
  147. return $PHPDateObject;
  148. } // function _adjustDateByMonths()
  149. /**
  150. * DATETIMENOW
  151. *
  152. * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
  153. * depending on the value of the ReturnDateType flag
  154. */
  155. public static function DATETIMENOW()
  156. {
  157. $saveTimeZone = date_default_timezone_get();
  158. date_default_timezone_set('UTC');
  159. $retValue = False;
  160. switch (PHPExcel_Calculation_Functions :: getReturnDateType())
  161. {
  162. case PHPExcel_Calculation_Functions :: RETURNDATE_EXCEL :
  163. $retValue = (float) PHPExcel_Shared_Date :: PHPToExcel(time());
  164. break;
  165. case PHPExcel_Calculation_Functions :: RETURNDATE_PHP_NUMERIC :
  166. $retValue = (integer) time();
  167. break;
  168. case PHPExcel_Calculation_Functions :: RETURNDATE_PHP_OBJECT :
  169. $retValue = new DateTime();
  170. break;
  171. }
  172. date_default_timezone_set($saveTimeZone);
  173. return $retValue;
  174. } // function DATETIMENOW()
  175. /**
  176. * DATENOW
  177. *
  178. * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
  179. * depending on the value of the ReturnDateType flag
  180. */
  181. public static function DATENOW()
  182. {
  183. $saveTimeZone = date_default_timezone_get();
  184. date_default_timezone_set('UTC');
  185. $retValue = False;
  186. $excelDateTime = floor(PHPExcel_Shared_Date :: PHPToExcel(time()));
  187. switch (PHPExcel_Calculation_Functions :: getReturnDateType())
  188. {
  189. case PHPExcel_Calculation_Functions :: RETURNDATE_EXCEL :
  190. $retValue = (float) $excelDateTime;
  191. break;
  192. case PHPExcel_Calculation_Functions :: RETURNDATE_PHP_NUMERIC :
  193. $retValue = (integer) PHPExcel_Shared_Date :: ExcelToPHP($excelDateTime) - 3600;
  194. break;
  195. case PHPExcel_Calculation_Functions :: RETURNDATE_PHP_OBJECT :
  196. $retValue = PHPExcel_Shared_Date :: ExcelToPHPObject($excelDateTime);
  197. break;
  198. }
  199. date_default_timezone_set($saveTimeZone);
  200. return $retValue;
  201. } // function DATENOW()
  202. /**
  203. * DATE
  204. *
  205. * @param long $year
  206. * @param long $month
  207. * @param long $day
  208. * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
  209. * depending on the value of the ReturnDateType flag
  210. */
  211. public static function DATE($year = 0, $month = 1, $day = 1)
  212. {
  213. $year = (integer) PHPExcel_Calculation_Functions :: flattenSingleValue($year);
  214. $month = (integer) PHPExcel_Calculation_Functions :: flattenSingleValue($month);
  215. $day = (integer) PHPExcel_Calculation_Functions :: flattenSingleValue($day);
  216. $baseYear = PHPExcel_Shared_Date :: getExcelCalendar();
  217. // Validate parameters
  218. if ($year < ($baseYear - 1900))
  219. {
  220. return PHPExcel_Calculation_Functions :: NaN();
  221. }
  222. if ((($baseYear - 1900) != 0) && ($year < $baseYear) && ($year >= 1900))
  223. {
  224. return PHPExcel_Calculation_Functions :: NaN();
  225. }
  226. if (($year < $baseYear) && ($year >= ($baseYear - 1900)))
  227. {
  228. $year += 1900;
  229. }
  230. if ($month < 1)
  231. {
  232. // Handle year/month adjustment if month < 1
  233. -- $month;
  234. $year += ceil($month / 12) - 1;
  235. $month = 13 - abs($month % 12);
  236. }
  237. elseif ($month > 12)
  238. {
  239. // Handle year/month adjustment if month > 12
  240. $year += floor($month / 12);
  241. $month = ($month % 12);
  242. }
  243. // Re-validate the year parameter after adjustments
  244. if (($year < $baseYear) || ($year >= 10000))
  245. {
  246. return PHPExcel_Calculation_Functions :: NaN();
  247. }
  248. // Execute function
  249. $excelDateValue = PHPExcel_Shared_Date :: FormattedPHPToExcel($year, $month, $day);
  250. switch (PHPExcel_Calculation_Functions :: getReturnDateType())
  251. {
  252. case PHPExcel_Calculation_Functions :: RETURNDATE_EXCEL :
  253. return (float) $excelDateValue;
  254. break;
  255. case PHPExcel_Calculation_Functions :: RETURNDATE_PHP_NUMERIC :
  256. return (integer) PHPExcel_Shared_Date :: ExcelToPHP($excelDateValue);
  257. break;
  258. case PHPExcel_Calculation_Functions :: RETURNDATE_PHP_OBJECT :
  259. return PHPExcel_Shared_Date :: ExcelToPHPObject($excelDateValue);
  260. break;
  261. }
  262. } // function DATE()
  263. /**
  264. * TIME
  265. *
  266. * @param long $hour
  267. * @param long $minute
  268. * @param long $second
  269. * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
  270. * depending on the value of the ReturnDateType flag
  271. */
  272. public static function TIME($hour = 0, $minute = 0, $second = 0)
  273. {
  274. $hour = PHPExcel_Calculation_Functions :: flattenSingleValue($hour);
  275. $minute = PHPExcel_Calculation_Functions :: flattenSingleValue($minute);
  276. $second = PHPExcel_Calculation_Functions :: flattenSingleValue($second);
  277. if ($hour == '')
  278. {
  279. $hour = 0;
  280. }
  281. if ($minute == '')
  282. {
  283. $minute = 0;
  284. }
  285. if ($second == '')
  286. {
  287. $second = 0;
  288. }
  289. if ((! is_numeric($hour)) || (! is_numeric($minute)) || (! is_numeric($second)))
  290. {
  291. return PHPExcel_Calculation_Functions :: VALUE();
  292. }
  293. $hour = (integer) $hour;
  294. $minute = (integer) $minute;
  295. $second = (integer) $second;
  296. if ($second < 0)
  297. {
  298. $minute += floor($second / 60);
  299. $second = 60 - abs($second % 60);
  300. if ($second == 60)
  301. {
  302. $second = 0;
  303. }
  304. }
  305. elseif ($second >= 60)
  306. {
  307. $minute += floor($second / 60);
  308. $second = $second % 60;
  309. }
  310. if ($minute < 0)
  311. {
  312. $hour += floor($minute / 60);
  313. $minute = 60 - abs($minute % 60);
  314. if ($minute == 60)
  315. {
  316. $minute = 0;
  317. }
  318. }
  319. elseif ($minute >= 60)
  320. {
  321. $hour += floor($minute / 60);
  322. $minute = $minute % 60;
  323. }
  324. if ($hour > 23)
  325. {
  326. $hour = $hour % 24;
  327. }
  328. elseif ($hour < 0)
  329. {
  330. return PHPExcel_Calculation_Functions :: NaN();
  331. }
  332. // Execute function
  333. switch (PHPExcel_Calculation_Functions :: getReturnDateType())
  334. {
  335. case PHPExcel_Calculation_Functions :: RETURNDATE_EXCEL :
  336. $date = 0;
  337. $calendar = PHPExcel_Shared_Date :: getExcelCalendar();
  338. if ($calendar != PHPExcel_Shared_Date :: CALENDAR_WINDOWS_1900)
  339. {
  340. $date = 1;
  341. }
  342. return (float) PHPExcel_Shared_Date :: FormattedPHPToExcel($calendar, 1, $date, $hour, $minute, $second);
  343. break;
  344. case PHPExcel_Calculation_Functions :: RETURNDATE_PHP_NUMERIC :
  345. return (integer) PHPExcel_Shared_Date :: ExcelToPHP(PHPExcel_Shared_Date :: FormattedPHPToExcel(1970, 1, 1, $hour - 1, $minute, $second)); // -2147468400; // -2147472000 + 3600
  346. break;
  347. case PHPExcel_Calculation_Functions :: RETURNDATE_PHP_OBJECT :
  348. $dayAdjust = 0;
  349. if ($hour < 0)
  350. {
  351. $dayAdjust = floor($hour / 24);
  352. $hour = 24 - abs($hour % 24);
  353. if ($hour == 24)
  354. {
  355. $hour = 0;
  356. }
  357. }
  358. elseif ($hour >= 24)
  359. {
  360. $dayAdjust = floor($hour / 24);
  361. $hour = $hour % 24;
  362. }
  363. $phpDateObject = new DateTime('1900-01-01 ' . $hour . ':' . $minute . ':' . $second);
  364. if ($dayAdjust != 0)
  365. {
  366. $phpDateObject->modify($dayAdjust . ' days');
  367. }
  368. return $phpDateObject;
  369. break;
  370. }
  371. } // function TIME()
  372. /**
  373. * DATEVALUE
  374. *
  375. * @param string $dateValue
  376. * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
  377. * depending on the value of the ReturnDateType flag
  378. */
  379. public static function DATEVALUE($dateValue = 1)
  380. {
  381. $dateValue = trim(PHPExcel_Calculation_Functions :: flattenSingleValue($dateValue), '"');
  382. // Strip any ordinals because they're allowed in Excel (English only)
  383. $dateValue = preg_replace('/(\d)(st|nd|rd|th)([ -\/])/Ui', '$1$3', $dateValue);
  384. // Convert separators (/ . or space) to hyphens (should also handle dot used for ordinals in some countries, e.g. Denmark, Germany)
  385. $dateValue = str_replace(array('/', '.', '-', ' '), array(' ', ' ', ' ', ' '), $dateValue);
  386. $yearFound = false;
  387. $t1 = explode(' ', $dateValue);
  388. foreach ($t1 as &$t)
  389. {
  390. if ((is_numeric($t)) && ($t > 31))
  391. {
  392. if ($yearFound)
  393. {
  394. return PHPExcel_Calculation_Functions :: VALUE();
  395. }
  396. else
  397. {
  398. if ($t < 100)
  399. {
  400. $t += 1900;
  401. }
  402. $yearFound = true;
  403. }
  404. }
  405. }
  406. if ((count($t1) == 1) && (strpos($t, ':') != false))
  407. {
  408. // We've been fed a time value without any date
  409. return 0.0;
  410. }
  411. elseif (count($t1) == 2)
  412. {
  413. // We only have two parts of the date: either day/month or month/year
  414. if ($yearFound)
  415. {
  416. array_unshift($t1, 1);
  417. }
  418. else
  419. {
  420. array_push($t1, date('Y'));
  421. }
  422. }
  423. unset($t);
  424. $dateValue = implode(' ', $t1);
  425. $PHPDateArray = date_parse($dateValue);
  426. if (($PHPDateArray === False) || ($PHPDateArray['error_count'] > 0))
  427. {
  428. $testVal1 = strtok($dateValue, '- ');
  429. if ($testVal1 !== False)
  430. {
  431. $testVal2 = strtok('- ');
  432. if ($testVal2 !== False)
  433. {
  434. $testVal3 = strtok('- ');
  435. if ($testVal3 === False)
  436. {
  437. $testVal3 = strftime('%Y');
  438. }
  439. }
  440. else
  441. {
  442. return PHPExcel_Calculation_Functions :: VALUE();
  443. }
  444. }
  445. else
  446. {
  447. return PHPExcel_Calculation_Functions :: VALUE();
  448. }
  449. $PHPDateArray = date_parse($testVal1 . '-' . $testVal2 . '-' . $testVal3);
  450. if (($PHPDateArray === False) || ($PHPDateArray['error_count'] > 0))
  451. {
  452. $PHPDateArray = date_parse($testVal2 . '-' . $testVal1 . '-' . $testVal3);
  453. if (($PHPDateArray === False) || ($PHPDateArray['error_count'] > 0))
  454. {
  455. return PHPExcel_Calculation_Functions :: VALUE();
  456. }
  457. }
  458. }
  459. if (($PHPDateArray !== False) && ($PHPDateArray['error_count'] == 0))
  460. {
  461. // Execute function
  462. if ($PHPDateArray['year'] == '')
  463. {
  464. $PHPDateArray['year'] = strftime('%Y');
  465. }
  466. if ($PHPDateArray['month'] == '')
  467. {
  468. $PHPDateArray['month'] = strftime('%m');
  469. }
  470. if ($PHPDateArray['day'] == '')
  471. {
  472. $PHPDateArray['day'] = strftime('%d');
  473. }
  474. $excelDateValue = floor(PHPExcel_Shared_Date :: FormattedPHPToExcel($PHPDateArray['year'], $PHPDateArray['month'], $PHPDateArray['day'], $PHPDateArray['hour'], $PHPDateArray['minute'], $PHPDateArray['second']));
  475. switch (PHPExcel_Calculation_Functions :: getReturnDateType())
  476. {
  477. case PHPExcel_Calculation_Functions :: RETURNDATE_EXCEL :
  478. return (float) $excelDateValue;
  479. break;
  480. case PHPExcel_Calculation_Functions :: RETURNDATE_PHP_NUMERIC :
  481. return (integer) PHPExcel_Shared_Date :: ExcelToPHP($excelDateValue);
  482. break;
  483. case PHPExcel_Calculation_Functions :: RETURNDATE_PHP_OBJECT :
  484. return new DateTime($PHPDateArray['year'] . '-' . $PHPDateArray['month'] . '-' . $PHPDateArray['day'] . ' 00:00:00');
  485. break;
  486. }
  487. }
  488. return PHPExcel_Calculation_Functions :: VALUE();
  489. } // function DATEVALUE()
  490. /**
  491. * TIMEVALUE
  492. *
  493. * @param string $timeValue
  494. * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
  495. * depending on the value of the ReturnDateType flag
  496. */
  497. public static function TIMEVALUE($timeValue)
  498. {
  499. $timeValue = trim(PHPExcel_Calculation_Functions :: flattenSingleValue($timeValue), '"');
  500. $timeValue = str_replace(array('/', '.'), array('-', '-'), $timeValue);
  501. $PHPDateArray = date_parse($timeValue);
  502. if (($PHPDateArray !== False) && ($PHPDateArray['error_count'] == 0))
  503. {
  504. if (PHPExcel_Calculation_Functions :: getCompatibilityMode() == PHPExcel_Calculation_Functions :: COMPATIBILITY_OPENOFFICE)
  505. {
  506. $excelDateValue = PHPExcel_Shared_Date :: FormattedPHPToExcel($PHPDateArray['year'], $PHPDateArray['month'], $PHPDateArray['day'], $PHPDateArray['hour'], $PHPDateArray['minute'], $PHPDateArray['second']);
  507. }
  508. else
  509. {
  510. $excelDateValue = PHPExcel_Shared_Date :: FormattedPHPToExcel(1900, 1, 1, $PHPDateArray['hour'], $PHPDateArray['minute'], $PHPDateArray['second']) - 1;
  511. }
  512. switch (PHPExcel_Calculation_Functions :: getReturnDateType())
  513. {
  514. case PHPExcel_Calculation_Functions :: RETURNDATE_EXCEL :
  515. return (float) $excelDateValue;
  516. break;
  517. case PHPExcel_Calculation_Functions :: RETURNDATE_PHP_NUMERIC :
  518. return (integer) $phpDateValue = PHPExcel_Shared_Date :: ExcelToPHP($excelDateValue + 25569) - 3600;
  519. ;
  520. break;
  521. case PHPExcel_Calculation_Functions :: RETURNDATE_PHP_OBJECT :
  522. return new DateTime('1900-01-01 ' . $PHPDateArray['hour'] . ':' . $PHPDateArray['minute'] . ':' . $PHPDateArray['second']);
  523. break;
  524. }
  525. }
  526. return PHPExcel_Calculation_Functions :: VALUE();
  527. } // function TIMEVALUE()
  528. /**
  529. * DATEDIF
  530. *
  531. * @param long $startDate Excel date serial value or a standard date string
  532. * @param long $endDate Excel date serial value or a standard date string
  533. * @param string $unit
  534. * @return long Interval between the dates
  535. */
  536. public static function DATEDIF($startDate = 0, $endDate = 0, $unit = 'D')
  537. {
  538. $startDate = PHPExcel_Calculation_Functions :: flattenSingleValue($startDate);
  539. $endDate = PHPExcel_Calculation_Functions :: flattenSingleValue($endDate);
  540. $unit = strtoupper(PHPExcel_Calculation_Functions :: flattenSingleValue($unit));
  541. if (is_string($startDate = self :: _getDateValue($startDate)))
  542. {
  543. return PHPExcel_Calculation_Functions :: VALUE();
  544. }
  545. if (is_string($endDate = self :: _getDateValue($endDate)))
  546. {
  547. return PHPExcel_Calculation_Functions :: VALUE();
  548. }
  549. // Validate parameters
  550. if ($startDate >= $endDate)
  551. {
  552. return PHPExcel_Calculation_Functions :: NaN();
  553. }
  554. // Execute function
  555. $difference = $endDate - $startDate;
  556. $PHPStartDateObject = PHPExcel_Shared_Date :: ExcelToPHPObject($startDate);
  557. $startDays = $PHPStartDateObject->format('j');
  558. $startMonths = $PHPStartDateObject->format('n');
  559. $startYears = $PHPStartDateObject->format('Y');
  560. $PHPEndDateObject = PHPExcel_Shared_Date :: ExcelToPHPObject($endDate);
  561. $endDays = $PHPEndDateObject->format('j');
  562. $endMonths = $PHPEndDateObject->format('n');
  563. $endYears = $PHPEndDateObject->format('Y');
  564. $retVal = PHPExcel_Calculation_Functions :: NaN();
  565. switch ($unit)
  566. {
  567. case 'D' :
  568. $retVal = intval($difference);
  569. break;
  570. case 'M' :
  571. $retVal = intval($endMonths - $startMonths) + (intval($endYears - $startYears) * 12);
  572. // We're only interested in full months
  573. if ($endDays < $startDays)
  574. {
  575. -- $retVal;
  576. }
  577. break;
  578. case 'Y' :
  579. $retVal = intval($endYears - $startYears);
  580. // We're only interested in full months
  581. if ($endMonths < $startMonths)
  582. {
  583. -- $retVal;
  584. }
  585. elseif (($endMonths == $startMonths) && ($endDays < $startDays))
  586. {
  587. -- $retVal;
  588. }
  589. break;
  590. case 'MD' :
  591. if ($endDays < $startDays)
  592. {
  593. $retVal = $endDays;
  594. $PHPEndDateObject->modify('-' . $endDays . ' days');
  595. $adjustDays = $PHPEndDateObject->format('j');
  596. if ($adjustDays > $startDays)
  597. {
  598. $retVal += ($adjustDays - $startDays);
  599. }
  600. }
  601. else
  602. {
  603. $retVal = $endDays - $startDays;
  604. }
  605. break;
  606. case 'YM' :
  607. $retVal = intval($endMonths - $startMonths);
  608. if ($retVal < 0)
  609. $retVal = 12 + $retVal;
  610. // We're only interested in full months
  611. if ($endDays < $startDays)
  612. {
  613. -- $retVal;
  614. }
  615. break;
  616. case 'YD' :
  617. $retVal = intval($difference);
  618. if ($endYears > $startYears)
  619. {
  620. while ($endYears > $startYears)
  621. {
  622. $PHPEndDateObject->modify('-1 year');
  623. $endYears = $PHPEndDateObject->format('Y');
  624. }
  625. $retVal = $PHPEndDateObject->format('z') - $PHPStartDateObject->format('z');
  626. if ($retVal < 0)
  627. {
  628. $retVal += 365;
  629. }
  630. }
  631. break;
  632. }
  633. return $retVal;
  634. } // function DATEDIF()
  635. /**
  636. * DAYS360
  637. *
  638. * @param long $startDate Excel date serial value or a standard date string
  639. * @param long $endDate Excel date serial value or a standard date string
  640. * @param boolean $method US or European Method
  641. * @return long PHP date/time serial
  642. */
  643. public static function DAYS360($startDate = 0, $endDate = 0, $method = false)
  644. {
  645. $startDate = PHPExcel_Calculation_Functions :: flattenSingleValue($startDate);
  646. $endDate = PHPExcel_Calculation_Functions :: flattenSingleValue($endDate);
  647. if (is_string($startDate = self :: _getDateValue($startDate)))
  648. {
  649. return PHPExcel_Calculation_Functions :: VALUE();
  650. }
  651. if (is_string($endDate = self :: _getDateValue($endDate)))
  652. {
  653. return PHPExcel_Calculation_Functions :: VALUE();
  654. }
  655. // Execute function
  656. $PHPStartDateObject = PHPExcel_Shared_Date :: ExcelToPHPObject($startDate);
  657. $startDay = $PHPStartDateObject->format('j');
  658. $startMonth = $PHPStartDateObject->format('n');
  659. $startYear = $PHPStartDateObject->format('Y');
  660. $PHPEndDateObject = PHPExcel_Shared_Date :: ExcelToPHPObject($endDate);
  661. $endDay = $PHPEndDateObject->format('j');
  662. $endMonth = $PHPEndDateObject->format('n');
  663. $endYear = $PHPEndDateObject->format('Y');
  664. return self :: _dateDiff360($startDay, $startMonth, $startYear, $endDay, $endMonth, $endYear, ! $method);
  665. } // function DAYS360()
  666. /**
  667. * YEARFRAC
  668. *
  669. * Calculates the fraction of the year represented by the number of whole days between two dates (the start_date and the
  670. * end_date). Use the YEARFRAC worksheet function to identify the proportion of a whole year's benefits or obligations
  671. * to assign to a specific term.
  672. *
  673. * @param mixed $startDate Excel date serial value (float), PHP date timestamp (integer) or date object, or a standard date string
  674. * @param mixed $endDate Excel date serial value (float), PHP date timestamp (integer) or date object, or a standard date string
  675. * @param integer $method Method used for the calculation
  676. * 0 or omitted US (NASD) 30/360
  677. * 1 Actual/actual
  678. * 2 Actual/360
  679. * 3 Actual/365
  680. * 4 European 30/360
  681. * @return float fraction of the year
  682. */
  683. public static function YEARFRAC($startDate = 0, $endDate = 0, $method = 0)
  684. {
  685. $startDate = PHPExcel_Calculation_Functions :: flattenSingleValue($startDate);
  686. $endDate = PHPExcel_Calculation_Functions :: flattenSingleValue($endDate);
  687. $method = PHPExcel_Calculation_Functions :: flattenSingleValue($method);
  688. if (is_string($startDate = self :: _getDateValue($startDate)))
  689. {
  690. return PHPExcel_Calculation_Functions :: VALUE();
  691. }
  692. if (is_string($endDate = self :: _getDateValue($endDate)))
  693. {
  694. return PHPExcel_Calculation_Functions :: VALUE();
  695. }
  696. if (((is_numeric($method)) && (! is_string($method))) || ($method == ''))
  697. {
  698. switch ($method)
  699. {
  700. case 0 :
  701. return self :: DAYS360($startDate, $endDate) / 360;
  702. break;
  703. case 1 :
  704. $days = self :: DATEDIF($startDate, $endDate);
  705. $startYear = self :: YEAR($startDate);
  706. $endYear = self :: YEAR($endDate);
  707. $years = $endYear - $startYear + 1;
  708. $leapDays = 0;
  709. if ($years == 1)
  710. {
  711. if (self :: _isLeapYear($endYear))
  712. {
  713. $startMonth = self :: MONTHOFYEAR($startDate);
  714. $endMonth = self :: MONTHOFYEAR($endDate);
  715. $endDay = self :: DAYOFMONTH($endDate);
  716. if (($startMonth < 3) || (($endMonth * 100 + $endDay) >= (2 * 100 + 29)))
  717. {
  718. $leapDays += 1;
  719. }
  720. }
  721. }
  722. else
  723. {
  724. for($year = $startYear; $year <= $endYear; ++ $year)
  725. {
  726. if ($year == $startYear)
  727. {
  728. $startMonth = self :: MONTHOFYEAR($startDate);
  729. $startDay = self :: DAYOFMONTH($startDate);
  730. if ($startMonth < 3)
  731. {
  732. $leapDays += (self :: _isLeapYear($year)) ? 1 : 0;
  733. }
  734. }
  735. elseif ($year == $endYear)
  736. {
  737. $endMonth = self :: MONTHOFYEAR($endDate);
  738. $endDay = self :: DAYOFMONTH($endDate);
  739. if (($endMonth * 100 + $endDay) >= (2 * 100 + 29))
  740. {
  741. $leapDays += (self :: _isLeapYear($year)) ? 1 : 0;
  742. }
  743. }
  744. else
  745. {
  746. $leapDays += (self :: _isLeapYear($year)) ? 1 : 0;
  747. }
  748. }
  749. if ($years == 2)
  750. {
  751. if (($leapDays == 0) && (self :: _isLeapYear($startYear)) && ($days > 365))
  752. {
  753. $leapDays = 1;
  754. }
  755. elseif ($days < 366)
  756. {
  757. $years = 1;
  758. }
  759. }
  760. $leapDays /= $years;
  761. }
  762. return $days / (365 + $leapDays);
  763. break;
  764. case 2 :
  765. return self :: DATEDIF($startDate, $endDate) / 360;
  766. break;
  767. case 3 :
  768. return self :: DATEDIF($startDate, $endDate) / 365;
  769. break;
  770. case 4 :
  771. return self :: DAYS360($startDate, $endDate, True) / 360;
  772. break;
  773. }
  774. }
  775. return PHPExcel_Calculation_Functions :: VALUE();
  776. } // function YEARFRAC()
  777. /**
  778. * NETWORKDAYS
  779. *
  780. * @param mixed Start date
  781. * @param mixed End date
  782. * @param array of mixed Optional Date Series
  783. * @return long Interval between the dates
  784. */
  785. public static function NETWORKDAYS($startDate, $endDate)
  786. {
  787. // Retrieve the mandatory start and end date that are referenced in the function definition
  788. $startDate = PHPExcel_Calculation_Functions :: flattenSingleValue($startDate);
  789. $endDate = PHPExcel_Calculation_Functions :: flattenSingleValue($endDate);
  790. // Flush the mandatory start and end date that are referenced in the function definition, and get the optional days
  791. $dateArgs = PHPExcel_Calculation_Functions :: flattenArray(func_get_args());
  792. array_shift($dateArgs);
  793. array_shift($dateArgs);
  794. // Validate the start and end dates
  795. if (is_string($startDate = $sDate = self :: _getDateValue($startDate)))
  796. {
  797. return PHPExcel_Calculation_Functions :: VALUE();
  798. }
  799. $startDate = (float) floor($startDate);
  800. if (is_string($endDate = $eDate = self :: _getDateValue($endDate)))
  801. {
  802. return PHPExcel_Calculation_Functions :: VALUE();
  803. }
  804. $endDate = (float) floor($endDate);
  805. if ($sDate > $eDate)
  806. {
  807. $startDate = $eDate;
  808. $endDate = $sDate;
  809. }
  810. // Execute function
  811. $startDoW = 6 - self :: DAYOFWEEK($startDate, 2);
  812. if ($startDoW < 0)
  813. {
  814. $startDoW = 0;
  815. }
  816. $endDoW = self :: DAYOFWEEK($endDate, 2);
  817. if ($endDoW >= 6)
  818. {
  819. $endDoW = 0;
  820. }
  821. $wholeWeekDays = floor(($endDate - $startDate) / 7) * 5;
  822. $partWeekDays = $endDoW + $startDoW;
  823. if ($partWeekDays > 5)
  824. {
  825. $partWeekDays -= 5;
  826. }
  827. // Test any extra holiday parameters
  828. $holidayCountedArray = array();
  829. foreach ($dateArgs as $holidayDate)
  830. {
  831. if (is_string($holidayDate = self :: _getDateValue($holidayDate)))
  832. {
  833. return PHPExcel_Calculation_Functions :: VALUE();
  834. }
  835. if (($holidayDate >= $startDate) && ($holidayDate <= $endDate))
  836. {
  837. if ((self :: DAYOFWEEK($holidayDate, 2) < 6) && (! in_array($holidayDate, $holidayCountedArray)))
  838. {
  839. -- $partWeekDays;
  840. $holidayCountedArray[] = $holidayDate;
  841. }
  842. }
  843. }
  844. if ($sDate > $eDate)
  845. {
  846. return 0 - ($wholeWeekDays + $partWeekDays);
  847. }
  848. return $wholeWeekDays + $partWeekDays;
  849. } // function NETWORKDAYS()
  850. /**
  851. * WORKDAY
  852. *
  853. * @param mixed Start date
  854. * @param mixed number of days for adjustment
  855. * @param array of mixed Optional Date Series
  856. * @return long Interval between the dates
  857. */
  858. public static function WORKDAY($startDate, $endDays)
  859. {
  860. // Retrieve the mandatory start date and days that are referenced in the function definition
  861. $startDate = PHPExcel_Calculation_Functions :: flattenSingleValue($startDate);
  862. $endDays = (int) PHPExcel_Calculation_Functions :: flattenSingleValue($endDays);
  863. // Flush the mandatory start date and days that are referenced in the function definition, and get the optional days
  864. $dateArgs = PHPExcel_Calculation_Functions :: flattenArray(func_get_args());
  865. array_shift($dateArgs);
  866. array_shift($dateArgs);
  867. if ((is_string($startDate = self :: _getDateValue($startDate))) || (! is_numeric($endDays)))
  868. {
  869. return PHPExcel_Calculation_Functions :: VALUE();
  870. }
  871. $startDate = (float) floor($startDate);
  872. // If endDays is 0, we always return startDate
  873. if ($endDays == 0)
  874. {
  875. return $startDate;
  876. }
  877. $decrementing = ($endDays < 0) ? True : False;
  878. // Adjust the start date if it falls over a weekend
  879. $startDoW = self :: DAYOFWEEK($startDate, 3);
  880. if (self :: DAYOFWEEK($startDate, 3) >= 5)
  881. {
  882. $startDate += ($decrementing) ? - $startDoW + 4 : 7 - $startDoW;
  883. ($decrementing) ? $endDays ++ : $endDays --;
  884. }
  885. // Add endDays
  886. $endDate = (float) $startDate + (intval($endDays / 5) * 7) + ($endDays % 5);
  887. // Adjust the calculated end date if it falls over a weekend
  888. $endDoW = self :: DAYOFWEEK($endDate, 3);
  889. if ($endDoW >= 5)
  890. {
  891. $endDate += ($decrementing) ? - $endDoW + 4 : 7 - $endDoW;
  892. }
  893. // Test any extra holiday parameters
  894. if (count($dateArgs) > 0)
  895. {
  896. $holidayCountedArray = $holidayDates = array();
  897. foreach ($dateArgs as $holidayDate)
  898. {
  899. if ((! is_null($holidayDate)) && (trim($holidayDate) > ''))
  900. {
  901. if (is_string($holidayDate = self :: _getDateValue($holidayDate)))
  902. {
  903. return PHPExcel_Calculation_Functions :: VALUE();
  904. }
  905. if (self :: DAYOFWEEK($holidayDate, 3) < 5)
  906. {
  907. $holidayDates[] = $holidayDate;
  908. }
  909. }
  910. }
  911. if ($decrementing)
  912. {
  913. rsort($holidayDates, SORT_NUMERIC);
  914. }
  915. else
  916. {
  917. sort($holidayDates, SORT_NUMERIC);
  918. }
  919. foreach ($holidayDates as $holidayDate)
  920. {
  921. if ($decrementing)
  922. {
  923. if (($holidayDate <= $startDate) && ($holidayDate >= $endDate))
  924. {
  925. if (! in_array($holidayDate, $holidayCountedArray))
  926. {
  927. -- $endDate;
  928. $holidayCountedArray[] = $holidayDate;
  929. }
  930. }
  931. }
  932. else
  933. {
  934. if (($holidayDate >= $startDate) && ($holidayDate <= $endDate))
  935. {
  936. if (! in_array($holidayDate, $holidayCountedArray))
  937. {
  938. ++ $endDate;
  939. $holidayCountedArray[] = $holidayDate;
  940. }
  941. }
  942. }
  943. // Adjust the calculated end date if it falls over a weekend
  944. $endDoW = self :: DAYOFWEEK($endDate, 3);
  945. if ($endDoW >= 5)
  946. {
  947. $endDate += ($decrementing) ? - $endDoW + 4 : 7 - $endDoW;
  948. }
  949. }
  950. }
  951. switch (PHPExcel_Calculation_Functions :: getReturnDateType())
  952. {
  953. case PHPExcel_Calculation_Functions :: RETURNDATE_EXCEL :
  954. return (float) $endDate;
  955. break;
  956. case PHPExcel_Calculation_Functions :: RETURNDATE_PHP_NUMERIC :
  957. return (integer) PHPExcel_Shared_Date :: ExcelToPHP($endDate);
  958. break;
  959. case PHPExcel_Calculation_Functions :: RETURNDATE_PHP_OBJECT :
  960. return PHPExcel_Shared_Date :: ExcelToPHPObject($endDate);
  961. break;
  962. }
  963. } // function WORKDAY()
  964. /**
  965. * DAYOFMONTH
  966. *
  967. * @param long $dateValue Excel date serial value or a standard date string
  968. * @return int Day
  969. */
  970. public static function DAYOFMONTH($dateValue = 1)
  971. {
  972. $dateValue = PHPExcel_Calculation_Functions :: flattenSingleValue($dateValue);
  973. if (is_string($dateValue = self :: _getDateValue($dateValue)))
  974. {
  975. return PHPExcel_Calculation_Functions :: VALUE();
  976. }
  977. elseif ($dateValue == 0.0)
  978. {
  979. return 0;
  980. }
  981. elseif ($dateValue < 0.0)
  982. {
  983. return PHPExcel_Calculation_Functions :: NaN();
  984. }
  985. // Execute function
  986. $PHPDateObject = PHPExcel_Shared_Date :: ExcelToPHPObject($dateValue);
  987. return (int) $PHPDateObject->format('j');
  988. } // function DAYOFMONTH()
  989. /**
  990. * DAYOFWEEK
  991. *
  992. * @param long $dateValue Excel date serial value or a standard date string
  993. * @return int Day
  994. */
  995. public static function DAYOFWEEK($dateValue = 1, $style = 1)
  996. {
  997. $dateValue = PHPExcel_Calculation_Functions :: flattenSingleValue($dateValue);
  998. $style = floor(PHPExcel_Calculation_Functions :: flattenSingleValue($style));
  999. if (is_string($dateValue = self :: _getDateValue($dateValue)))
  1000. {
  1001. return PHPExcel_Calculation_Functions :: VALUE();
  1002. }
  1003. elseif ($dateValue < 0.0)
  1004. {
  1005. return PHPExcel_Calculation_Functions :: NaN();
  1006. }
  1007. // Execute function
  1008. $PHPDateObject = PHPExcel_Shared_Date :: ExcelToPHPObject($dateValue);
  1009. $DoW = $PHPDateObject->format('w');
  1010. $firstDay = 1;
  1011. switch ($style)
  1012. {
  1013. case 1 :
  1014. ++ $DoW;
  1015. break;
  1016. case 2 :
  1017. if ($DoW == 0)
  1018. {
  1019. $DoW = 7;
  1020. }
  1021. break;
  1022. case 3 :
  1023. if ($DoW == 0)
  1024. {
  1025. $DoW = 7;
  1026. }
  1027. $firstDay = 0;
  1028. -- $DoW;
  1029. break;
  1030. default :
  1031. }
  1032. if (PHPExcel_Calculation_Functions :: getCompatibilityMode() == PHPExcel_Calculation_Functions :: COMPATIBILITY_EXCEL)
  1033. {
  1034. // Test for Excel's 1900 leap year, and introduce the error as required
  1035. if (($PHPDateObject->format('Y') == 1900) && ($PHPDateObject->format('n') <= 2))
  1036. {
  1037. -- $DoW;
  1038. if ($DoW < $firstDay)
  1039. {
  1040. $DoW += 7;
  1041. }
  1042. }
  1043. }
  1044. return (int) $DoW;
  1045. } // function DAYOFWEEK()
  1046. /**
  1047. * WEEKOFYEAR
  1048. *
  1049. * @param long $dateValue Excel date serial value or a standard date string
  1050. * @param boolean $method Week begins on Sunday or Monday
  1051. * @return int Week Number
  1052. */
  1053. public static function WEEKOFYEAR($dateValue = 1, $method = 1)
  1054. {
  1055. $dateValue = PHPExcel_Calculation_Functions :: flattenSingleValue($dateValue);
  1056. $method = floor(PHPExcel_Calculation_Functions :: flattenSingleValue($method));
  1057. if (! is_numeric($method))
  1058. {
  1059. return PHPExcel_Calculation_Functions :: VALUE();
  1060. }
  1061. elseif (($method < 1) || ($method > 2))
  1062. {
  1063. return PHPExcel_Calculation_Functions :: NaN();
  1064. }
  1065. if (is_string($dateValue = self :: _getDateValue($dateValue)))
  1066. {
  1067. return PHPExcel_Calculation_Functions :: VALUE();
  1068. }
  1069. elseif ($dateValue < 0.0)
  1070. {
  1071. return PHPExcel_Calculation_Functions :: NaN();
  1072. }
  1073. // Execute function
  1074. $PHPDateObject = PHPExcel_Shared_Date :: ExcelToPHPObject($dateValue);
  1075. $dayOfYear = $PHPDateObject->format('z');
  1076. $dow = $PHPDateObject->format('w');
  1077. $PHPDateObject->modify('-' . $dayOfYear . ' days');
  1078. $dow = $PHPDateObject->format('w');
  1079. $daysInFirstWeek = 7 - (($dow + (2 - $method)) % 7);
  1080. $dayOfYear -= $daysInFirstWeek;
  1081. $weekOfYear = ceil($dayOfYear / 7) + 1;
  1082. return (int) $weekOfYear;
  1083. } // function WEEKOFYEAR()
  1084. /**
  1085. * MONTHOFYEAR
  1086. *
  1087. * @param long $dateValue Excel date serial value or a standard date string
  1088. * @return int Month
  1089. */
  1090. public static function MONTHOFYEAR($dateValue = 1)
  1091. {
  1092. $dateValue = PHPExcel_Calculation_Functions :: flattenSingleValue($dateValue);
  1093. if (is_string($dateValue = self :: _getDateValue($dateValue)))
  1094. {
  1095. return PHPExcel_Calculation_Functions :: VALUE();
  1096. }
  1097. elseif ($dateValue < 0.0)
  1098. {
  1099. return PHPExcel_Calculation_Functions :: NaN();
  1100. }
  1101. // Execute function
  1102. $PHPDateObject = PHPExcel_Shared_Date :: ExcelToPHPObject($dateValue);
  1103. return (int) $PHPDateObject->format('n');
  1104. } // function MONTHOFYEAR()
  1105. /**
  1106. * YEAR
  1107. *
  1108. * @param long $dateValue Excel date serial value or a standard date string
  1109. * @return int Year
  1110. */
  1111. public static function YEAR($dateValue = 1)
  1112. {
  1113. $dateValue = PHPExcel_Calculation_Functions :: flattenSingleValue($dateValue);
  1114. if (is_string($dateValue = self :: _getDateValue($dateValue)))
  1115. {
  1116. return PHPExcel_Calculation_Functions :: VALUE();
  1117. }
  1118. elseif ($dateValue < 0.0)
  1119. {
  1120. return PHPExcel_Calculation_Functions :: NaN();
  1121. }
  1122. // Execute function
  1123. $PHPDateObject = PHPExcel_Shared_Date :: ExcelToPHPObject($dateValue);
  1124. return (int) $PHPDateObject->format('Y');
  1125. } // function YEAR()
  1126. /**
  1127. * HOUROFDAY
  1128. *
  1129. * @param mixed $timeValue Excel time serial value or a standard time string
  1130. * @return int Hour
  1131. */
  1132. public static function HOUROFDAY($timeValue = 0)
  1133. {
  1134. $timeValue = PHPExcel_Calculation_Functions :: flattenSingleValue($timeValue);
  1135. if (! is_numeric($timeValue))
  1136. {
  1137. if (PHPExcel_Calculation_Functions :: getCompatibilityMode() == PHPExcel_Calculation_Functions :: COMPATIBILITY_GNUMERIC)
  1138. {
  1139. $testVal = strtok($timeValue, '/-: ');
  1140. if (strlen($testVal) < strlen($timeValue))
  1141. {
  1142. return PHPExcel_Calculation_Functions :: VALUE();
  1143. }
  1144. }
  1145. $timeValue = self :: _getTimeValue($timeValue);
  1146. if (is_string($timeValue))
  1147. {
  1148. return PHPExcel_Calculation_Functions :: VALUE();
  1149. }
  1150. }
  1151. // Execute function
  1152. if ($timeValue >= 1)
  1153. {
  1154. $timeValue = fmod($timeValue, 1);
  1155. }
  1156. elseif ($timeValue < 0.0)
  1157. {
  1158. return PHPExcel_Calculation_Functions :: NaN();
  1159. }
  1160. $timeValue = PHPExcel_Shared_Date :: ExcelToPHP($timeValue);
  1161. return (int) gmdate('G', $timeValue);
  1162. } // function HOUROFDAY()
  1163. /**
  1164. * MINUTEOFHOUR
  1165. *
  1166. * @param long $timeValue Excel time serial value or a standard time string
  1167. * @return int Minute
  1168. */
  1169. public static function MINUTEOFHOUR($timeValue = 0)
  1170. {
  1171. $timeValue = $timeTester = PHPExcel_Calculation_Functions :: flattenSingleValue($timeValue);
  1172. if (! is_numeric($timeValue))
  1173. {
  1174. if (PHPExcel_Calculation_Functions :: getCompatibilityMode() == PHPExcel_Calculation_Functions :: COMPATIBILITY_GNUMERIC)
  1175. {
  1176. $testVal = strtok($timeValue, '/-: ');
  1177. if (strlen($testVal) < strlen($timeValue))
  1178. {
  1179. return PHPExcel_Calculation_Functions :: VALUE();
  1180. }
  1181. }
  1182. $timeValue = self :: _getTimeValue($timeValue);
  1183. if (is_string($timeValue))
  1184. {
  1185. return PHPExcel_Calculation_Functions :: VALUE();
  1186. }
  1187. }
  1188. // Execute function
  1189. if ($timeValue >= 1)
  1190. {
  1191. $timeValue = fmod($timeValue, 1);
  1192. }
  1193. elseif ($timeValue < 0.0)
  1194. {
  1195. return PHPExcel_Calculation_Functions :: NaN();
  1196. }
  1197. $timeValue = PHPExcel_Shared_Date :: ExcelToPHP($timeValue);
  1198. return (int) gmdate('i', $timeValue);
  1199. } // function MINUTEOFHOUR()
  1200. /**
  1201. * SECONDOFMINUTE
  1202. *
  1203. * @param long $timeValue Excel time serial value or a standard time string
  1204. * @return int Second
  1205. */
  1206. public static function SECONDOFMINUTE($timeValue = 0)
  1207. {
  1208. $timeValue = PHPExcel_Calculation_Functions :: flattenSingleValue($timeValue);
  1209. if (! is_numeric($timeValue))
  1210. {
  1211. if (PHPExcel_Calculation_Functions :: getCompatibilityMode() == PHPExcel_Calculation_Functions :: COMPATIBILITY_GNUMERIC)
  1212. {
  1213. $testVal = strtok($timeValue, '/-: ');
  1214. if (strlen($testVal) < strlen($timeValue))
  1215. {
  1216. return PHPExcel_Calculation_Functions :: VALUE();
  1217. }
  1218. }
  1219. $timeValue = self :: _getTimeValue($timeValue);
  1220. if (is_string($timeValue))
  1221. {
  1222. return PHPExcel_Calculation_Functions :: VALUE();
  1223. }
  1224. }
  1225. // Execute function
  1226. if ($timeValue >= 1)
  1227. {
  1228. $timeValue = fmod($timeValue, 1);
  1229. }
  1230. e

Large files files are truncated, but you can click here to view the full file