Commit f9b34ed907cd2330e1602ea8628b9625410cfcf2

Authored by Nathanaël Jourdane
1 parent ed15f51c

import : parse dates with non-standard formats

Showing 1 changed file with 7 additions and 4 deletions   Show diff stats
php/classes/TimeTableMgr.php
... ... @@ -333,13 +333,13 @@ class TimeTableMgr extends AmdaObjectMgr
333 333 $descNumber = 0;
334 334  
335 335 foreach ($lines as $line) {
336   - $line = preg_replace('/\s+/', ' ', 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   - $doyRegex = '(\d{4}) (\d{2,3}) (\d{2}) (\d{2}) (\d{2})( \d{2})?';
  342 + $doyRegex = '(\d{4}) (\d{3}) (\d{2}) (\d{2}) (\d{2})( \d{2})?';
343 343  
344 344 if (preg_match('/^' . $doyRegex . ' ' . $doyRegex . '$/', $line)) {
345 345 $start = DateTime::createFromFormat($doyFormat, substr($line, 0, 17));
... ... @@ -349,8 +349,11 @@ class TimeTableMgr extends AmdaObjectMgr
349 349 } else {
350 350 $dateLength = round((strlen($line)-1) / 2);
351 351  
352   - $startTime = strtotime(substr($line, 0, $dateLength));
353   - $stopTime = strtotime(substr($line, $dateLength + 1));
  352 + $start = explode(' ', substr($line, 0, $dateLength) . ' 00');
  353 + $startTime = strtotime("$start[0]/$start[1]/$start[2] $start[3]:$start[4]:$start[5]");
  354 +
  355 + $stop = explode(' ', substr($line, $dateLength + 1) . ' 00');
  356 + $stopTime = strtotime("$stop[0]/$stop[1]/$stop[2] $stop[3]:$stop[4]:$stop[5]");
354 357 if (is_numeric($startTime) && is_numeric($stopTime)) {
355 358 $startDate = date($isoFormat, $startTime);
356 359 $stopDate = date($isoFormat, $stopTime);
... ...