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); } + ?>