Commit 703f403fed4abdda83b79db5a27767cebf08896e

Authored by Benjamin Renard
1 parent acc7504d

Fix some bugs with time parsing in request

src/InputOutput/IHMImpl/Params/PlotImpl/IHMInputOutputParamsPlotClass.php
@@ -1800,8 +1800,8 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass @@ -1800,8 +1800,8 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass
1800 "file-output" => "INTERACTIVE", 1800 "file-output" => "INTERACTIVE",
1801 "file-prefix" => "instant", 1801 "file-prefix" => "instant",
1802 "timesrc" => "Interval", 1802 "timesrc" => "Interval",
1803 - "startDate" => date("Y-m-dTH:i:s", $timeStamp - 3600),  
1804 - "stopDate" => date("Y-m-dTH:i:s", $timeStamp + 3600), 1803 + "startDate" => date("Y-m-d\TH:i:s", $timeStamp - 3600),
  1804 + "stopDate" => date("Y-m-d\TH:i:s", $timeStamp + 3600),
1805 "id" => 1, 1805 "id" => 1,
1806 "page-margins-activated" => $plotInput->{"page-margins-activated"}, 1806 "page-margins-activated" => $plotInput->{"page-margins-activated"},
1807 "page-margin-x" => $plotInput->{"page-margin-x"}, 1807 "page-margin-x" => $plotInput->{"page-margin-x"},
@@ -1899,7 +1899,7 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass @@ -1899,7 +1899,7 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass
1899 { 1899 {
1900 date_default_timezone_set('UTC'); 1900 date_default_timezone_set('UTC');
1901 $timeStamp = strtotime($input->starttime); 1901 $timeStamp = strtotime($input->starttime);
1902 - $DATE_TYPE = "Y-m-dTH:i:s"; 1902 + $DATE_TYPE = "Y-m-d\TH:i:s";
1903 $start_time_plotfunction = date($DATE_TYPE, $timeStamp); 1903 $start_time_plotfunction = date($DATE_TYPE, $timeStamp);
1904 $timestamp_stop_plotfunction = strtotime($input->stoptime); 1904 $timestamp_stop_plotfunction = strtotime($input->stoptime);
1905 $stop_time_plotfunction = date($DATE_TYPE, $timestamp_stop_plotfunction); 1905 $stop_time_plotfunction = date($DATE_TYPE, $timestamp_stop_plotfunction);
src/InputOutput/IHMImpl/Tools/CommonClass.php
@@ -23,6 +23,7 @@ class CommonClass @@ -23,6 +23,7 @@ class CommonClass
23 */ 23 */
24 public static function timeStampToDDTime($timeStamp) 24 public static function timeStampToDDTime($timeStamp)
25 { 25 {
  26 + $mls = intval($timeStamp*1000)-intval($timeStamp)*1000;
26 $y = date("Y",$timeStamp); 27 $y = date("Y",$timeStamp);
27 $d = date("z",$timeStamp); 28 $d = date("z",$timeStamp);
28 if (strlen($d) == 0) 29 if (strlen($d) == 0)
@@ -31,19 +32,25 @@ class CommonClass @@ -31,19 +32,25 @@ class CommonClass
31 $d = "00".$d; 32 $d = "00".$d;
32 else if (strlen($d) == 2) 33 else if (strlen($d) == 2)
33 $d = "0".$d; 34 $d = "0".$d;
34 - $t = date("His",$timeStamp)."000"; 35 + $t = date("His",$timeStamp).str_pad($mls, 3, '0', STR_PAD_LEFT);
35 return $y.$d.$t; 36 return $y.$d.$t;
36 } 37 }
  38 +
  39 + public static function isoToTimeStampWithMls($iso)
  40 + {
  41 + date_default_timezone_set('UTC');
  42 + $date = DateTime::createFromFormat('Y-m-d\TH:i:s.v', $iso);
  43 + if ($date !== FALSE) {
  44 + return round(floatval($date->format('v'))/1000. + $date->getTimestamp(),3);
  45 + }
  46 + $date = DateTime::createFromFormat('Y-m-d\TH:i:s', $iso);
  47 + return round(floatval($date->getTimestamp()),3);
  48 + }
37 49
38 - public static function getDurationDDTime($strStop, $strStart) 50 + public static function getDurationDDTime($strStop, $strStart)
39 { 51 {
40 -  
41 - $timeStamp = strtotime($strStop) - strtotime($strStart);  
42 -  
43 - $diffMs = CommonClass::getMsIntFromStrTime($strStop) - CommonClass::getMsIntFromStrTime($strStart);  
44 - $duration =CommonClass::timeStampToDDTime($timeStamp);  
45 -  
46 - return str_pad(strval((intval($duration) + $diffMs)),16,'0', STR_PAD_LEFT); 52 + $timeStamp = round(CommonClass::isoToTimeStampWithMls($strStop) - CommonClass::isoToTimeStampWithMls($strStart),3);
  53 + return CommonClass::timeStampToDDTime($timeStamp);
47 } 54 }
48 55
49 public static function getMsIntFromStrTime($strTime){ 56 public static function getMsIntFromStrTime($strTime){
@@ -84,7 +91,7 @@ class CommonClass @@ -84,7 +91,7 @@ class CommonClass
84 */ 91 */
85 public static function DDTimeToTimeStamp($DDTime) 92 public static function DDTimeToTimeStamp($DDTime)
86 { 93 {
87 - date_default_timezone_set('UTC'); 94 + date_default_timezone_set('UTC');
88 $date = DateTime::createFromFormat('YzHisu', $DDTime); 95 $date = DateTime::createFromFormat('YzHisu', $DDTime);
89 96
90 return strtotime($date->format("Y-m-d\TH:i:s.u")); 97 return strtotime($date->format("Y-m-d\TH:i:s.u"));
@@ -132,4 +139,4 @@ class CommonClass @@ -132,4 +139,4 @@ class CommonClass
132 } 139 }
133 } 140 }
134 141
135 -?>  
136 \ No newline at end of file 142 \ No newline at end of file
  143 +?>