Last active
August 29, 2015 14:09
-
-
Save feload/eb3c2960b4be9134c0ba to your computer and use it in GitHub Desktop.
Human readable elapsed time.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function time_elapsed_string($ptime){ | |
$etime = time() - $ptime; | |
if ($etime < 1) | |
return '0 seconds'; | |
$a = array( 12 * 30 * 24 * 60 * 60 => 'año', | |
30 * 24 * 60 * 60 => 'meses', | |
24 * 60 * 60 => 'día', | |
60 * 60 => 'hora', | |
60 => 'minuto', | |
1 => 'segundo' | |
); | |
foreach ($a as $secs => $str) { | |
$d = $etime / $secs; | |
if ($d >= 1) | |
{ | |
$r = round($d); | |
if($r > 1) | |
{ | |
$end = ($str == 'mes') ? 'es' : 's'; | |
} | |
return "Hace {$r} {$str}{$end}"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment