From d5d84d8a78e3cb2a20a0aa496e5f2911167cd11f Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 21 Feb 2019 21:47:38 +0100 Subject: [dnbd3] Show image idle time in proxy details --- inc/util.inc.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'inc') diff --git a/inc/util.inc.php b/inc/util.inc.php index e459cc46..06cd8981 100644 --- a/inc/util.inc.php +++ b/inc/util.inc.php @@ -512,4 +512,25 @@ SADFACE; return date('d.m.Y', $ts); } + /** + * Format a duration, in seconds, into a readable string. + * @param int $seconds The number to format + * @param int $showSecs whether to show seconds, or rather cut after minutes + * @return string + */ + public static function formatDuration($seconds, $showSecs = true) + { + settype($seconds, 'int'); + static $UNITS = ['y' => 31536000, 'mon' => 2592000, 'd' => 86400]; + $parts = []; + foreach ($UNITS as $k => $v) { + if ($seconds < $v) + continue; + $n = floor($seconds / $v); + $seconds -= $n * $v; + $parts[] = $n. $k; + } + return implode(' ', $parts) . ' ' . gmdate($showSecs ? 'H:i:s' : 'H:i', $seconds); + } + } -- cgit v1.2.3-55-g7522