From daa50f8f84630c87d20c5dc04f77ae065474470f Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 27 Aug 2020 14:45:57 +0200 Subject: [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. --- inc/util.inc.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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); } -- cgit v1.2.3-55-g7522