Commit 6bea1021acdb7e90e08a7f9eb82281d5ceeb02b5

Authored by Myriam Bouchemit
1 parent c54497a2

Parse partial ISO time

Showing 1 changed file with 14 additions and 0 deletions   Show diff stats
src/InputOutput/IHMImpl/Tools/CommonClass.php
... ... @@ -39,11 +39,25 @@ class CommonClass
39 39 public static function isoToTimeStampWithMls($iso)
40 40 {
41 41 date_default_timezone_set('UTC');
  42 + $iso = trim($iso);
  43 + if (empty($iso)) {
  44 + return 0.;
  45 + }
  46 + else if ($iso[strlen($iso)-1] == 'Z') {
  47 + $iso = substr($iso, 0, -1);
  48 + }
42 49 $date = DateTime::createFromFormat('Y-m-d\TH:i:s.v', $iso);
43 50 if ($date !== FALSE) {
44 51 return round(floatval($date->format('v'))/1000. + $date->getTimestamp(),3);
45 52 }
46 53 $date = DateTime::createFromFormat('Y-m-d\TH:i:s', $iso);
  54 + if ($date !== FALSE) {
  55 + return round(floatval($date->getTimestamp()),3);
  56 + }
  57 + $date = DateTime::createFromFormat('Y-m-d\TH:i', $iso);
  58 + if ($date === FALSE) {
  59 + return 0.;
  60 + }
47 61 return round(floatval($date->getTimestamp()),3);
48 62 }
49 63  
... ...