mirror of
https://github.com/ShaYmez/ezservermonitor-web.git
synced 2024-12-22 01:20:58 -05:00
Uptime : more readable
This commit is contained in:
parent
a935f5ece1
commit
c384224e0a
@ -69,6 +69,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
|
||||
*
|
||||
|
@ -31,22 +31,7 @@ if (!($totalSeconds = shell_exec('/usr/bin/cut -d. -f1 /proc/uptime')))
|
||||
}
|
||||
else
|
||||
{
|
||||
$totalMin = $totalSeconds / 60;
|
||||
$totalHours = $totalMin / 60;
|
||||
|
||||
$days = floor($totalHours / 24);
|
||||
$hours = floor($totalHours - ($days * 24));
|
||||
$min = floor($totalMin - ($days * 60 * 24) - ($hours * 60));
|
||||
|
||||
$uptime = '';
|
||||
if ($days != 0)
|
||||
$uptime .= $days.' day'.Misc::pluralize($days).' ';
|
||||
|
||||
if ($hours != 0)
|
||||
$uptime .= $hours.' hour'.Misc::pluralize($hours).' ';
|
||||
|
||||
if ($min != 0)
|
||||
$uptime .= $min.' minute'.Misc::pluralize($min);
|
||||
$uptime = Misc::getHumanTime($totalSeconds);
|
||||
}
|
||||
|
||||
// Last boot
|
||||
|
Loading…
Reference in New Issue
Block a user