public function PersianDate::ago in Persian Date for Drupal 8 8
Same name and namespace in other branches
- 8.4 src/Converter/PersianDate.php \Drupal\persian_date\Converter\PersianDate::ago()
File
- src/Converter/PersianDate.php, line 328
Class
- PersianDate
- This class hold time and represents it in Persian Date format.
Namespace
Drupal\persian_date\Converter
Code
public function ago() {
$now = time();
$time = $this
->getTimestamp();
if (!$time) {
return false;
}
$periods = array(
'ثانیه',
'دقیقه',
'ساعت',
'روز',
'هفته',
'ماه',
'سال',
'قرن',
);
$lengths = array(
60,
60,
24,
7,
4.35,
12,
10,
);
$difference = $now - $time;
if ($difference < 0) {
$difference = abs($difference);
$negative = true;
}
for ($j = 0; $difference >= $lengths[$j] and $j < count($lengths) - 1; $j++) {
$difference /= $lengths[$j];
}
$difference = intval(round($difference));
return number_format($difference) . ' ' . $periods[$j] . ' ' . (isset($negative) ? '' : 'پیش');
}