Second zu Zeitumwandlung robuster gegen ungültige Zahlen gemacht
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user