Skip to content

Instantly share code, notes, and snippets.

@raisiqueira
Created April 30, 2015 01:13
Show Gist options
  • Save raisiqueira/9cc1367f133e6df3bf3f to your computer and use it in GitHub Desktop.
Save raisiqueira/9cc1367f133e6df3bf3f to your computer and use it in GitHub Desktop.
Função "time ago"
<?php
//http://codeforgeek.com/2014/10/time-ago-implementation-php/
function get_timeago( $ptime )
{
$estimate_time = time() - $ptime;
if( $estimate_time < 1 )
{
return 'less than 1 second ago';
}
$condition = array(
12 * 30 * 24 * 60 * 60 => 'year',
30 * 24 * 60 * 60 => 'month',
24 * 60 * 60 => 'day',
60 * 60 => 'hour',
60 => 'minute',
1 => 'second'
);
foreach( $condition as $secs => $str )
{
$d = $estimate_time / $secs;
if( $d >= 1 )
{
$r = round( $d );
return 'about ' . $r . ' ' . $str . ( $r > 1 ? 's' : '' ) . ' ago';
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment