summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2020-08-27 14:45:57 +0200
committerSimon Rettberg2020-08-27 15:06:10 +0200
commitdaa50f8f84630c87d20c5dc04f77ae065474470f (patch)
tree16c66d04f0871565afc9264df5423fb5d0ca88d9
parent[rebootcontrol] busybox timeout was patched to behave like coreutils (diff)
downloadslx-admin-daa50f8f84630c87d20c5dc04f77ae065474470f.tar.gz
slx-admin-daa50f8f84630c87d20c5dc04f77ae065474470f.tar.xz
slx-admin-daa50f8f84630c87d20c5dc04f77ae065474470f.zip
[inc/Util] formatDuration: Add leading zero
Conditionally add leading zero to years, months, days if we printed the next-larger unit already, for beeter display in tables.
-rw-r--r--inc/util.inc.php8
1 files changed, 7 insertions, 1 deletions
diff --git a/inc/util.inc.php b/inc/util.inc.php
index 83b2d54a..365dc045 100644
--- a/inc/util.inc.php
+++ b/inc/util.inc.php
@@ -529,12 +529,18 @@ SADFACE;
settype($seconds, 'int');
static $UNITS = ['y' => 31536000, 'mon' => 2592000, 'd' => 86400];
$parts = [];
+ $prev = false;
foreach ($UNITS as $k => $v) {
if ($seconds < $v)
continue;
$n = floor($seconds / $v);
$seconds -= $n * $v;
- $parts[] = $n. $k;
+ if ($prev) {
+ $parts[] = sprintf('%02d', $n) . $k;
+ } else {
+ $parts[] = $n . $k;
+ $prev = true;
+ }
}
return implode(' ', $parts) . ' ' . gmdate($showSecs ? 'H:i:s' : 'H:i', $seconds);
}