How could I alter this function so it prints the minutes unit alone?
What I mean is:
Right now it's
This was 7 second ago
-- Couple minutes later --
This was 5 minute 8 second ago
But I want this:
This was 7 second ago
-- Couple minutes later --
This was 5 minute ago ( i dont care about the seconds )
Also how could I check if its plural? So it will ad an S after the unit?
The function:
function humanTiming($time)
{
$time = time() - $time; // to get the time since that moment
$tokens = array (
31536000 => 'year',
2592000 => 'month',
604800 => 'week',
86400 => 'day',
3600 => 'hour',
60 => 'minute',
1 => 'second'
);
$result = '';
$counter = 1;
foreach ($tokens as $unit => $text) {
if ($time < $unit) continue;
if ($counter > 2) break;
$numberOfUnits = floor($time / $unit);
$result .= "$numberOfUnits $text ";
$time -= $numberOfUnits * $unit;
++$counter;
}
return "This was {$result} ago";
}