summaryrefslogtreecommitdiff
path: root/libs/Utils/Misc.php
diff options
context:
space:
mode:
authorShevAbam <shevabam@gmail.com>2015-07-16 15:24:17 +0200
committerShevAbam <shevabam@gmail.com>2015-07-16 15:24:17 +0200
commitc384224e0a0dbea61745595a2cb63664b6d2fd84 (patch)
tree2964a0f3d27af9242cad18a9d6f744686267fde6 /libs/Utils/Misc.php
parenta935f5ece1d4b3738ad7b085d8dfebfbfc04cef0 (diff)
Uptime : more readable
Diffstat (limited to 'libs/Utils/Misc.php')
-rw-r--r--libs/Utils/Misc.php41
1 files changed, 41 insertions, 0 deletions
diff --git a/libs/Utils/Misc.php b/libs/Utils/Misc.php
index a86312b..37e578b 100644
--- a/libs/Utils/Misc.php
+++ b/libs/Utils/Misc.php
@@ -70,6 +70,47 @@ class Misc
/**
+ * Seconds to human readable text
+ * Eg: for 36545627 seconds => 1 year, 57 days, 23 hours and 33 minutes
+ *
+ * @return string Text
+ */
+ public static function getHumanTime($seconds)
+ {
+ $units = array(
+ 'year' => 365*86400,
+ 'day' => 86400,
+ 'hour' => 3600,
+ 'minute' => 60,
+ // 'second' => 1,
+ );
+
+ $parts = array();
+
+ foreach ($units as $name => $divisor)
+ {
+ $div = floor($seconds / $divisor);
+
+ if ($div == 0)
+ continue;
+ else
+ if ($div == 1)
+ $parts[] = $div.' '.$name;
+ else
+ $parts[] = $div.' '.$name.'s';
+ $seconds %= $divisor;
+ }
+
+ $last = array_pop($parts);
+
+ if (empty($parts))
+ return $last;
+ else
+ return join(', ', $parts).' and '.$last;
+ }
+
+
+ /**
* Returns a command that exists in the system among $cmds
*
* @param array $cmds List of commands