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) {
|
function getTimeFromSeconds($seconds): string {
|
||||||
$hours = floor($timestring / 3600);
|
if ($seconds === null || $seconds === '') {
|
||||||
$mins = floor($timestring / 60 % 60);
|
return '';
|
||||||
$secs = floor($timestring % 60);
|
}
|
||||||
$timeFormat = sprintf('%02d:%02d', $hours, $mins);
|
|
||||||
return $timeFormat;
|
// 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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -295,15 +295,35 @@ function echoMarkedTimeLine(?string $dateStr, ?int $timeSeconds, DateTimeImmutab
|
|||||||
echo $cls ? "</span>" : "";
|
echo $cls ? "</span>" : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
function getTimeFromSeconds(string $timestring) {
|
function getTimeFromSeconds(string $timestring) {
|
||||||
|
|
||||||
$hours = floor($timestring / 3600);
|
$hours = floor($timestring / 3600);
|
||||||
$mins = floor($timestring / 60 % 60);
|
$mins = floor(round($timestring / 60 % 60));
|
||||||
$secs = floor($timestring % 60);
|
$secs = floor(round($timestring % 60));
|
||||||
|
|
||||||
$timeFormat = sprintf('%02d:%02d', $hours, $mins);
|
$timeFormat = sprintf('%02d:%02d', $hours, $mins);
|
||||||
|
|
||||||
return $timeFormat;
|
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