Skip to content

Commit

Permalink
Added an option for human time which will display "54 seconds/minutes…
Browse files Browse the repository at this point in the history
…/etc ago"
  • Loading branch information
kripz authored and cdhowie committed Jul 5, 2011
1 parent 20876d3 commit 358163d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
31 changes: 26 additions & 5 deletions htdocs/common.inc.php
Expand Up @@ -189,15 +189,36 @@ function get_tempdata($key)
return $value;
}

function format_date($date)
function human_time($difference)
{
global $BTC_PROXY;
$postfix = array("second", "minute", "hour", "day", "week", "month", "year");
$lengths = array(60, 60, 24, 7, 4.3452380952380952380952380952381, 12);

for($i = 0; $difference >= $lengths[$i]; $i++)
$difference /= $lengths[$i];

$obj = new DateTime($date, new DateTimeZone('UTC'));
$difference = round($difference);

$obj->setTimezone(new DateTimeZone($BTC_PROXY['timezone']));
if($difference != 1)
$postfix[$i] .= "s";

return $obj->format($BTC_PROXY['date_format']);
return "$difference $postfix[$i] ago";
}

function format_date($date)
{
global $BTC_PROXY;
$obj = new DateTime($date, new DateTimeZone('UTC'));
$obj->setTimezone(new DateTimeZone($BTC_PROXY['timezone']));

if($BTC_PROXY['date_format'] != "human")
return $obj->format($BTC_PROXY['date_format']);
else
{
$now = new DateTime("now", new DateTimeZone('UTC'));
$now->setTimezone(new DateTimeZone($BTC_PROXY['timezone']));
$timespan = $now->getTimestamp() - $obj->getTimestamp();
return human_time($timespan);
}
}
?>
1 change: 1 addition & 0 deletions htdocs/config.inc.php.sample
Expand Up @@ -17,6 +17,7 @@ $BTC_PROXY = array(

# See <http://www.php.net/manual/en/timezones.php> for a list of timezones
'timezone' => 'UTC',
# Custom date format 'Y-m-d H:i:s T' or 'human' for human readable time "54 seconds ago"
'date_format' => 'Y-m-d H:i:s T',

# Number of seconds to consider when calculating number of shares and
Expand Down

0 comments on commit 358163d

Please sign in to comment.