ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
TimeValue.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use Datetime;
8 
9 class TimeValue
10 {
32  public static function fromString($timeValue)
33  {
34  $timeValue = trim(Functions::flattenSingleValue($timeValue), '"');
35  $timeValue = str_replace(['/', '.'], '-', $timeValue);
36 
37  $arraySplit = preg_split('/[\/:\-\s]/', $timeValue) ?: [];
38  if ((count($arraySplit) == 2 || count($arraySplit) == 3) && $arraySplit[0] > 24) {
39  $arraySplit[0] = ($arraySplit[0] % 24);
40  $timeValue = implode(':', $arraySplit);
41  }
42 
43  $PHPDateArray = date_parse($timeValue);
44  $retValue = Functions::VALUE();
45  if (($PHPDateArray !== false) && ($PHPDateArray['error_count'] == 0)) {
46  // OpenOffice-specific code removed - it works just like Excel
47  $excelDateValue = SharedDateHelper::formattedPHPToExcel(1900, 1, 1, $PHPDateArray['hour'], $PHPDateArray['minute'], $PHPDateArray['second']) - 1;
48 
49  $retType = Functions::getReturnDateType();
50  if ($retType === Functions::RETURNDATE_EXCEL) {
51  $retValue = (float) $excelDateValue;
52  } elseif ($retType === Functions::RETURNDATE_UNIX_TIMESTAMP) {
53  $retValue = (int) $phpDateValue = SharedDateHelper::excelToTimestamp($excelDateValue + 25569) - 3600;
54  } else {
55  $retValue = new DateTime('1900-01-01 ' . $PHPDateArray['hour'] . ':' . $PHPDateArray['minute'] . ':' . $PHPDateArray['second']);
56  }
57  }
58 
59  return $retValue;
60  }
61 }
static getReturnDateType()
Return the current Return Date Format for functions that return a date/time (Excel, PHP Serialized Numeric or PHP Object).
Definition: Functions.php:133
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
Definition: Functions.php:649