summaryrefslogtreecommitdiffstats
path: root/inc/util.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2020-08-27 14:45:57 +0200
committerSimon Rettberg2020-08-27 14:45:57 +0200
commit31b0256d525f550970d749b2cdcee89f1988e042 (patch)
tree5286203425b848eb94d519843289b177b3eff0ee /inc/util.inc.php
parent[rebootcontrol] busybox timeout was patched to behave like coreutils (diff)
downloadslx-admin-31b0256d525f550970d749b2cdcee89f1988e042.tar.gz
slx-admin-31b0256d525f550970d749b2cdcee89f1988e042.tar.xz
slx-admin-31b0256d525f550970d749b2cdcee89f1988e042.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.
Diffstat (limited to 'inc/util.inc.php')
-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);
}