diff options
author | Simon Rettberg | 2020-08-27 14:45:57 +0200 |
---|---|---|
committer | Simon Rettberg | 2020-08-27 14:45:57 +0200 |
commit | 31b0256d525f550970d749b2cdcee89f1988e042 (patch) | |
tree | 5286203425b848eb94d519843289b177b3eff0ee /inc/util.inc.php | |
parent | [rebootcontrol] busybox timeout was patched to behave like coreutils (diff) | |
download | slx-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.php | 8 |
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); } |