Improve "prettyTime()"
This commit is contained in:
@@ -73,28 +73,54 @@ 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)
|
||||||
{
|
{
|
||||||
$days = intval($secs / 86400);
|
if(!defined('SECOND')) define("SECOND", 1);
|
||||||
$hours = intval($secs / 3600 % 24);
|
if(!defined('MINUTE')) define("MINUTE", 60 * SECOND);
|
||||||
$minutes = intval($secs / 60 % 60);
|
if(!defined('HOUR')) define("HOUR", 60 * MINUTE);
|
||||||
$seconds = intval($secs % 60);
|
if(!defined('DAY')) define("DAY", 24 * HOUR);
|
||||||
if (($minutes + $hours + $days) < 1)
|
if(!defined('MONTH')) define("MONTH", 30 * DAY);
|
||||||
return (sprintf(_('%d seconds'), $seconds));
|
|
||||||
else if (($minutes + $hours) < 1)
|
if ($secs < 1 * MINUTE)
|
||||||
$string = sprintf(_('%d minutes'), $minutes);
|
{
|
||||||
else if ($days < 1)
|
return sprintf(ngettext('one second ago', '%d seconds ago', $secs), $secs);
|
||||||
$string = sprintf(_('%d hours, %d minutes'), $hours, $minutes);
|
}
|
||||||
|
if ($secs < 2 * MINUTE)
|
||||||
|
{
|
||||||
|
return _('a minute ago');
|
||||||
|
}
|
||||||
|
if ($secs < 45 * MINUTE)
|
||||||
|
{
|
||||||
|
return _('%d minutes ago', floor($secs / MINUTE));
|
||||||
|
}
|
||||||
|
if ($secs < 90 * MINUTE)
|
||||||
|
{
|
||||||
|
return _('an hour ago');
|
||||||
|
}
|
||||||
|
if ($secs < 24 * HOUR)
|
||||||
|
{
|
||||||
|
return _('%d hours ago', floor($secs / HOUR));
|
||||||
|
}
|
||||||
|
if ($secs < 48 * HOUR)
|
||||||
|
{
|
||||||
|
return _('yesterday');
|
||||||
|
}
|
||||||
|
if ($secs < 30 * DAY)
|
||||||
|
{
|
||||||
|
return sprintf(_('%d days ago'), floor($secs / DAY));
|
||||||
|
}
|
||||||
|
if ($secs < 12 * MONTH)
|
||||||
|
{
|
||||||
|
$months = floor($secs / DAY / 30);
|
||||||
|
return sprintf(ngettext('one month ago', '%d months ago', $months), $months);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
$string = sprintf(_('%d days, %d hours, %d minutes'), $days, $hours,
|
{
|
||||||
$minutes);
|
$years = floor($secs / DAY / 365);
|
||||||
|
return sprintf(ngettext('one year ago', '%d years ago', $years), $years);
|
||||||
if ($includeseconds)
|
}
|
||||||
$string .= ' ' . sprintf(_('and %d seconds'), $seconds);
|
|
||||||
|
|
||||||
return $string;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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