Commit efb5795428caad8ac851b98f1a66796a1d4010d5
1 parent
e4fba9d2
Exists in
master
and in
109 other branches
Parse imported time-table dates better
Showing
1 changed file
with
14 additions
and
9 deletions
Show diff stats
php/classes/TimeTableMgr.php
... | ... | @@ -333,25 +333,30 @@ class TimeTableMgr extends AmdaObjectMgr |
333 | 333 | $descNumber = 0; |
334 | 334 | |
335 | 335 | foreach ($lines as $line) { |
336 | - $line = trim($line); | |
336 | + $line = preg_replace('/\s+/', ' ', trim($line)); | |
337 | 337 | if ($line[0] == '#') { // Comment |
338 | 338 | $description = $description . PHP_EOL . substr($line, 1, -1); |
339 | 339 | } else { |
340 | 340 | $isoFormat = 'Y-m-dTH:i:s'; |
341 | 341 | $doyFormat = 'Y z H i s'; |
342 | - $isoRegex = '(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})'; | |
343 | 342 | $doyRegex = '(\d{4}) (\d{3}) (\d{2}) (\d{2}) (\d{2})'; |
344 | 343 | |
345 | - if (preg_match('/^' . $isoRegex . ' ' . $isoRegex . '$/', $line)) { | |
346 | - $startDate = substr($line, 0, 19); | |
347 | - $stopDate = substr($line, 20); | |
348 | - } elseif (preg_match('/^' . $doyRegex . ' ' . $doyRegex . '$/', $line)) { | |
344 | + if (preg_match('/^' . $doyRegex . ' ' . $doyRegex . '$/', $line)) { | |
349 | 345 | $startDate = DateTime::createFromFormat($doyFormat, substr($line, 0, 17))->format($isoFormat); |
350 | 346 | $stopDate = DateTime::createFromFormat($doyFormat, substr($line, 18))->format($isoFormat); |
351 | 347 | } else { |
352 | - $description = $description . PHP_EOL . $line; | |
353 | - $descNumber++; | |
354 | - continue; | |
348 | + $dateLength = round((strlen($line)-1) / 2); | |
349 | + | |
350 | + $startTime = strtotime(substr($line, 0, $dateLength)); | |
351 | + $stopTime = strtotime(substr($line, $dateLength + 1)); | |
352 | + if (is_numeric($startTime) && is_numeric($stopTime)) { | |
353 | + $startDate = date($isoFormat, $startTime); | |
354 | + $stopDate = date($isoFormat, $stopTime); | |
355 | + } else { | |
356 | + $description = $description . PHP_EOL . $line; | |
357 | + $descNumber++; | |
358 | + continue; | |
359 | + } | |
355 | 360 | } |
356 | 361 | |
357 | 362 | if (!$onlyDescription) { | ... | ... |