diff --git a/site/plugins/helpers/index.php b/site/plugins/helpers/index.php index fb94ee8..ec46509 100644 --- a/site/plugins/helpers/index.php +++ b/site/plugins/helpers/index.php @@ -174,10 +174,19 @@ function saveMapadoEvent($mapadoEvent, $page) { function getEndTime($session) { $formattedTime = strlen($session['time']) < 4 ? $session['time'] . '00' : $session['time']; - $time1 = DateTime::createFromFormat('G\hi', $formattedTime); + $time1 = DateTime::createFromFormat('Hi', $formattedTime); + if ($time1 === false) { + throw new Exception('format d\'heure invalide : ' . $session['time']); + } + $formattedDuration = strlen($session['duration']) < 4 ? $session['duration'] . '00' : $session['duration']; - $time2 = DateTime::createFromFormat('G\hi', $formattedDuration); + $time2 = DateTime::createFromFormat('Hi', $formattedDuration); + if ($time2 === false) { + throw new Exception('format de durée invalide : ' . $session['duration']); + } + $time1->add(new DateInterval('PT' . $time2->format('H') . 'H' . $time2->format('i') . 'M')); - $endTime = $time1->format('G\hi'); - return $endTime; + + return $time1->format('H:i'); } + diff --git a/site/templates/program.php b/site/templates/program.php index e0d2d1b..f1a56cc 100644 --- a/site/templates/program.php +++ b/site/templates/program.php @@ -76,7 +76,7 @@ try { $endTime = strlen($session['duration']) > 0 ? getEndTime($session) : false; } catch (\Throwable $th) { - throw new Exception($session['title'], 1); + throw new Exception($session['title'] .' - ' . $th->getMessage(), 1); } ?>