From 703f403fed4abdda83b79db5a27767cebf08896e Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Mon, 5 Sep 2022 09:56:13 +0200 Subject: [PATCH] Fix some bugs with time parsing in request --- src/InputOutput/IHMImpl/Params/PlotImpl/IHMInputOutputParamsPlotClass.php | 6 +++--- src/InputOutput/IHMImpl/Tools/CommonClass.php | 29 ++++++++++++++++++----------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/InputOutput/IHMImpl/Params/PlotImpl/IHMInputOutputParamsPlotClass.php b/src/InputOutput/IHMImpl/Params/PlotImpl/IHMInputOutputParamsPlotClass.php index 2b18711..74253b5 100644 --- a/src/InputOutput/IHMImpl/Params/PlotImpl/IHMInputOutputParamsPlotClass.php +++ b/src/InputOutput/IHMImpl/Params/PlotImpl/IHMInputOutputParamsPlotClass.php @@ -1800,8 +1800,8 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass "file-output" => "INTERACTIVE", "file-prefix" => "instant", "timesrc" => "Interval", - "startDate" => date("Y-m-dTH:i:s", $timeStamp - 3600), - "stopDate" => date("Y-m-dTH:i:s", $timeStamp + 3600), + "startDate" => date("Y-m-d\TH:i:s", $timeStamp - 3600), + "stopDate" => date("Y-m-d\TH:i:s", $timeStamp + 3600), "id" => 1, "page-margins-activated" => $plotInput->{"page-margins-activated"}, "page-margin-x" => $plotInput->{"page-margin-x"}, @@ -1899,7 +1899,7 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass { date_default_timezone_set('UTC'); $timeStamp = strtotime($input->starttime); - $DATE_TYPE = "Y-m-dTH:i:s"; + $DATE_TYPE = "Y-m-d\TH:i:s"; $start_time_plotfunction = date($DATE_TYPE, $timeStamp); $timestamp_stop_plotfunction = strtotime($input->stoptime); $stop_time_plotfunction = date($DATE_TYPE, $timestamp_stop_plotfunction); diff --git a/src/InputOutput/IHMImpl/Tools/CommonClass.php b/src/InputOutput/IHMImpl/Tools/CommonClass.php index f70b568..9b32287 100644 --- a/src/InputOutput/IHMImpl/Tools/CommonClass.php +++ b/src/InputOutput/IHMImpl/Tools/CommonClass.php @@ -23,6 +23,7 @@ class CommonClass */ public static function timeStampToDDTime($timeStamp) { + $mls = intval($timeStamp*1000)-intval($timeStamp)*1000; $y = date("Y",$timeStamp); $d = date("z",$timeStamp); if (strlen($d) == 0) @@ -31,19 +32,25 @@ class CommonClass $d = "00".$d; else if (strlen($d) == 2) $d = "0".$d; - $t = date("His",$timeStamp)."000"; + $t = date("His",$timeStamp).str_pad($mls, 3, '0', STR_PAD_LEFT); return $y.$d.$t; } + + public static function isoToTimeStampWithMls($iso) + { + date_default_timezone_set('UTC'); + $date = DateTime::createFromFormat('Y-m-d\TH:i:s.v', $iso); + if ($date !== FALSE) { + return round(floatval($date->format('v'))/1000. + $date->getTimestamp(),3); + } + $date = DateTime::createFromFormat('Y-m-d\TH:i:s', $iso); + return round(floatval($date->getTimestamp()),3); + } - public static function getDurationDDTime($strStop, $strStart) + public static function getDurationDDTime($strStop, $strStart) { - - $timeStamp = strtotime($strStop) - strtotime($strStart); - - $diffMs = CommonClass::getMsIntFromStrTime($strStop) - CommonClass::getMsIntFromStrTime($strStart); - $duration =CommonClass::timeStampToDDTime($timeStamp); - - return str_pad(strval((intval($duration) + $diffMs)),16,'0', STR_PAD_LEFT); + $timeStamp = round(CommonClass::isoToTimeStampWithMls($strStop) - CommonClass::isoToTimeStampWithMls($strStart),3); + return CommonClass::timeStampToDDTime($timeStamp); } public static function getMsIntFromStrTime($strTime){ @@ -84,7 +91,7 @@ class CommonClass */ public static function DDTimeToTimeStamp($DDTime) { - date_default_timezone_set('UTC'); + date_default_timezone_set('UTC'); $date = DateTime::createFromFormat('YzHisu', $DDTime); return strtotime($date->format("Y-m-d\TH:i:s.u")); @@ -132,4 +139,4 @@ class CommonClass } } -?> \ No newline at end of file +?> -- libgit2 0.21.2