From bc76739320f6e45cd9abc7dd3452a1423d60f1c9 Mon Sep 17 00:00:00 2001 From: Leopold Strobl Date: Wed, 29 Oct 2025 11:58:00 +0100 Subject: [PATCH] =?UTF-8?q?Second=20zu=20Zeitumwandlung=20robuster=20gegen?= =?UTF-8?q?=20ung=C3=BCltige=20Zahlen=20gemacht?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sources/getCheckInTable.php | 23 +++++++++++++++++------ sources/getCheckOutTable.php | 24 ++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/sources/getCheckInTable.php b/sources/getCheckInTable.php index 7bebc26..9984929 100644 --- a/sources/getCheckInTable.php +++ b/sources/getCheckInTable.php @@ -263,10 +263,21 @@ foreach ($data_output as $packingjob) { } } -function getTimeFromSeconds(string $timestring) { - $hours = floor($timestring / 3600); - $mins = floor($timestring / 60 % 60); - $secs = floor($timestring % 60); - $timeFormat = sprintf('%02d:%02d', $hours, $mins); - return $timeFormat; +function getTimeFromSeconds($seconds): string { + if ($seconds === null || $seconds === '') { + return ''; + } + + // robust normalisieren: String/Float -> Float -> gerundet -> Int + $seconds = (int) round((float) $seconds); + + if ($seconds < 0) { + $seconds = 0; // oder: return ''; je nach gewünschtem Verhalten + } + + // reine Integer-Arithmetik, keine impliziten float->int Casts + $hours = intdiv($seconds, 3600); + $mins = intdiv($seconds % 3600, 60); + + return sprintf('%02d:%02d', $hours, $mins); } diff --git a/sources/getCheckOutTable.php b/sources/getCheckOutTable.php index 01221e3..9c027cf 100644 --- a/sources/getCheckOutTable.php +++ b/sources/getCheckOutTable.php @@ -295,15 +295,35 @@ function echoMarkedTimeLine(?string $dateStr, ?int $timeSeconds, DateTimeImmutab echo $cls ? "" : ""; } +/* function getTimeFromSeconds(string $timestring) { $hours = floor($timestring / 3600); - $mins = floor($timestring / 60 % 60); - $secs = floor($timestring % 60); + $mins = floor(round($timestring / 60 % 60)); + $secs = floor(round($timestring % 60)); $timeFormat = sprintf('%02d:%02d', $hours, $mins); return $timeFormat; +}*/ +function getTimeFromSeconds($seconds): string { + if ($seconds === null || $seconds === '') { + return ''; + } + + // robust normalisieren: String/Float -> Float -> gerundet -> Int + $seconds = (int) round((float) $seconds); + + if ($seconds < 0) { + $seconds = 0; // oder: return ''; je nach gewünschtem Verhalten + } + + // reine Integer-Arithmetik, keine impliziten float->int Casts + $hours = intdiv($seconds, 3600); + $mins = intdiv($seconds % 3600, 60); + + return sprintf('%02d:%02d', $hours, $mins); } + ?>