public function createdAgo(\DateTime $dateTime)
{
$delta = time() - $dateTime->getTimestamp();
if ($delta < 0)
throw new \InvalidArgumentException("createdAgo is unable to handle dates in the future");
$duration = "";
if ($delta < 60)
{
$time = $delta;
$duration = $time . " секунд" . (($time > 1) ? "ы" : "") . " назад";
}
else if ($delta <= 3600)
{
$time = floor($delta / 60);
$duration = $time . " минут" . (($time > 1) ? "ы" : "") . " назад";
}
else if ($delta <= 86400)
{
$time = floor($delta / 3600);
$duration = $time . " час" . (($time > 1) ? "ов" : "") . " назад";
}
else
{
$time = floor($delta / 86400);
$duration = $time . " дн" . (($time > 1) ? "ей" : "") . " назад";
}
return $duration;
}
А с месяцев и годом не работает, кто дополнит?