Last active
August 29, 2015 14:23
-
-
Save samuraee/0b83bb62ada94b9f6c56 to your computer and use it in GitHub Desktop.
This file contains 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 ago($tm, $lang = 'fa', $ashtml = true) { | |
$local = array('style' => array('fa' => 'style="<a href="http://direction:rtl">direction:rtl</a>;"', | |
'en' => 'style="<a href="http://direction:ltr">direction:ltr</a>"'), | |
'times' => array( | |
'fa' => array('ثانیه', 'دقیقه', 'ساعت', 'روز', 'هفته', 'ماه', 'سال', 'دهه'), | |
'en' => array('second', 'minute', 'hour', 'day', 'week', 'month', 'year', 'decade')), | |
'ago' => array('fa' => 'پیش', 'en' => 'ago')); | |
if (intval($tm) > 0) { | |
$cur_tm = time(); | |
$dif = $cur_tm - $tm; | |
$lngh = array(1, 60, 3600, 86400, 604800, 2630880, 31570560, 315705600); | |
for ($v = sizeof($lngh) - 1; ($v >= 0) && (($no = $dif / $lngh[$v]) <= 1); $v--) | |
; if ($v < 0) | |
$v = 0; $_tm = $cur_tm - ($dif % $lngh[$v]); | |
$no = floor($no); | |
if ($no <> 1 && $lang == 'en') | |
$local['times'][$lang][$v] .= 's'; $x = sprintf("%d %s ", $no, $local['times'][$lang][$v]); | |
if ($ashtml) | |
return " " . $x . ' ' . $local['ago'][$lang] . ""; | |
else | |
return $x . ' ' . $local['ago'][$lang]; | |
} else { | |
return '-'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment