diff --git a/php/classes/TimeTableMgr.php b/php/classes/TimeTableMgr.php index 0669649..54b4419 100644 --- a/php/classes/TimeTableMgr.php +++ b/php/classes/TimeTableMgr.php @@ -114,16 +114,6 @@ class TimeTableMgr extends AmdaObjectMgr if ($key == 'created') { $rootElement->appendChild($this->objectDom->createElement($key, $this->created)); } - /*else if ($key == 'intervals') { - $n_int = 0; - foreach ($value as $item) { - $newInterval = $this->objectDom->createElement('intervals'); - $newInterval->appendChild($this->objectDom->createElement('start', $item->start)); - $newInterval->appendChild($this->objectDom->createElement('stop', $item->stop)); - $rootElement->appendChild($newInterval); - $n_int++; - } - }*/ // it is catalog else if ($key == 'parameters') { $paramsElement = $this->setParamDescription($value); @@ -161,28 +151,39 @@ class TimeTableMgr extends AmdaObjectMgr $lines = file($tmp_file,FILE_SKIP_EMPTY_LINES); $description="Uploaded Time Table".PHP_EOL; - foreach ($lines as $line){ - if ($line[0] == '#') $description=$description.PHP_EOL.substr($line,1,-1); + foreach ($lines as $line) + { + if ($line[0] == '#') { + $description=$description.PHP_EOL.substr($line,1,-1); + } else { - $date = explode(' ', preg_replace('!\s+!', ' ', $line)); + $date = explode(' ', trim(preg_replace('!\s+!', ' ',$line))); + if (!strtotime(trim($date[0]))) { $description=$description.PHP_EOL.$line; continue; } // check if it is ISO format - if (!isset($isIso)) $isIso = preg_match('/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})$/', trim($date[0])); + if (!isset($isIso)) + $isIso = preg_match('/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})$/', trim($date[0])); + if (!$isIso) { - if (count($date) == 2) { - $tempStartT = strtotime(trim($date[0])); - $tempStopT = strtotime(trim($date[1])); - } - else { // y-m-d h:m:s for example - $tempStartT = strtotime($date[0]." ".$date[1]); - $tempStopT = strtotime($date[2]." ".$date[3]); - } + // y-m-d h:m:s for example + $dateLength = count($date) / 2; + + $tempStart = $date[0]; + $tempStop = $date[$dateLength]; - $startDate = date('Y-m-d\TH:i:s',$tempStartT); - $stopDate = date('Y-m-d\TH:i:s',$tempStopT); + if ($dateLength > 1) { + for ($i = 1; $i < $dateLength; $i++) + $tempStart.= $date[$i]; + + for ($i = $dateLength + 1; $i < $dateLength * 2; $i++) + $tempStop .= $date[$i]; + } + + $startDate = date('Y-m-d\TH:i:s',strtotime($tempStart)); + $stopDate = date('Y-m-d\TH:i:s',strtotime($tempStop)); if (!$onlyDescription) $attributesToReturn['intervals'][] = array('start' => $startDate, 'stop' => $stopDate); @@ -193,15 +194,14 @@ class TimeTableMgr extends AmdaObjectMgr } } } - + $attributesToReturn['description'] = $description; $attributesToReturn['name'] = basename($tmp_file, '.'.$suffix[1]); $attributesToReturn['created'] = date('Y-m-d\TH:i:s'); return $attributesToReturn; } - - + /* * Uploaded vot TT => convert to array */ -- libgit2 0.21.2