summaryrefslogtreecommitdiffstats
path: root/inc
diff options
context:
space:
mode:
authorSimon Rettberg2019-02-21 21:47:38 +0100
committerSimon Rettberg2019-02-21 21:47:38 +0100
commitd5d84d8a78e3cb2a20a0aa496e5f2911167cd11f (patch)
tree92a3fff18a9bec837a05db182b0294c8dbf19abc /inc
parent[statistics] Improve display of non-client runmode machines (diff)
downloadslx-admin-d5d84d8a78e3cb2a20a0aa496e5f2911167cd11f.tar.gz
slx-admin-d5d84d8a78e3cb2a20a0aa496e5f2911167cd11f.tar.xz
slx-admin-d5d84d8a78e3cb2a20a0aa496e5f2911167cd11f.zip
[dnbd3] Show image idle time in proxy details
Diffstat (limited to 'inc')
-rw-r--r--inc/util.inc.php21
1 files changed, 21 insertions, 0 deletions
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);
+ }
+
}