Merge branch 'master' of disposed.de:scattport
This commit is contained in:
@@ -73,28 +73,42 @@ if ( ! function_exists('time_diff'))
|
|||||||
* @param boolean $includeseconds should seconds be appended to the string?
|
* @param boolean $includeseconds should seconds be appended to the string?
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
if ( ! function_exists('secondsToString'))
|
if ( ! function_exists('prettyTime'))
|
||||||
{
|
{
|
||||||
function secondsToString($secs, $includeseconds = false)
|
function prettyTime($secs, $includeseconds = false)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if(!defined('SECOND')) define("SECOND", 1);
|
||||||
|
if(!defined('MINUTE')) define("MINUTE", 60 * SECOND);
|
||||||
|
if(!defined('HOUR')) define("HOUR", 60 * MINUTE);
|
||||||
|
if(!defined('DAY')) define("DAY", 24 * HOUR);
|
||||||
|
if(!defined('MONTH')) define("MONTH", 30 * DAY);
|
||||||
|
|
||||||
$days = intval($secs / 86400);
|
$days = intval($secs / 86400);
|
||||||
$hours = intval($secs / 3600 % 24);
|
$hours = intval($secs / 3600 % 24);
|
||||||
$minutes = intval($secs / 60 % 60);
|
$minutes = intval($secs / 60 % 60);
|
||||||
$seconds = intval($secs % 60);
|
$seconds = intval($secs % 60);
|
||||||
if (($minutes + $hours + $days) < 1)
|
|
||||||
return (sprintf(_('%d seconds'), $seconds));
|
$d = sprintf(ngettext('%d day', '%d days', $days), $days);
|
||||||
else if (($minutes + $hours) < 1)
|
$h = sprintf(ngettext('%d hour', '%d hours', $hours), $hours);
|
||||||
$string = sprintf(_('%d minutes'), $minutes);
|
$m = sprintf(ngettext('%d minute', '%d minutes', $minutes), $minutes);
|
||||||
else if ($days < 1)
|
$s = sprintf(ngettext('%d second', '%d seconds', $seconds), $seconds);
|
||||||
$string = sprintf(_('%d hours, %d minutes'), $hours, $minutes);
|
|
||||||
else
|
$output = "";
|
||||||
$string = sprintf(_('%d days, %d hours, %d minutes'), $days, $hours,
|
if($days > 0) {
|
||||||
$minutes);
|
$output .= $d;
|
||||||
|
}
|
||||||
if ($includeseconds)
|
if($hours > 0) {
|
||||||
$string .= ' ' . sprintf(_('and %d seconds'), $seconds);
|
$output .= !empty($output) ? ", ". $h : "". $h;
|
||||||
|
}
|
||||||
return $string;
|
if($minutes > 0) {
|
||||||
|
$output .= !empty($output) ? ", ". $m : "". $m;
|
||||||
|
}
|
||||||
|
if($includeseconds || empty($output)) {
|
||||||
|
$output .= !empty($output) ? ", ". $s : "". $s;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -103,9 +103,8 @@ class Server extends CI_Model {
|
|||||||
public function getById($serverId) {
|
public function getById($serverId) {
|
||||||
$this->load->helper('date');
|
$this->load->helper('date');
|
||||||
$server = $this->db->get_where('servers', array('id' => $serverId))->row();
|
$server = $this->db->get_where('servers', array('id' => $serverId))->row();
|
||||||
$server->uptimestring = secondsToString($server->uptime);
|
$server->uptimestring = prettyTime($server->uptime);
|
||||||
$server->lastheartbeat = sprintf(_('%s ago'),
|
$server->lastheartbeat = prettyTime(time_diff($server->last_update, mysql_now()));
|
||||||
secondsToString(time_diff($server->last_update, mysql_now())));
|
|
||||||
return $server;
|
return $server;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user