/** * @param Activity $a * @param Activity $b * @return int */ public static function compare($a, $b) { if (strtotime($a->getCreated()->format("Y-m-d H:i:s")) === strtotime($b->getCreated()->format("Y-m-d H:i:s"))) { return 0; } return strtotime($a->getCreated()->format("Y-m-d H:i:s")) < strtotime($b->getCreated()->format("Y-m-d H:i:s")) ? 1 : -1; }
/** * @param Activity $activity * @return string */ private function renderActivityTime($activity) { $seconds = strtotime(date('Y-m-d H:i:s')) - strtotime($activity->getCreated()->format('Y-m-d H:i:s')); $months = floor($seconds / (3600 * 24 * 30)); $day = floor($seconds / (3600 * 24)); $hours = floor($seconds / 3600); $mins = floor(($seconds - $hours * 3600) / 60); $secs = floor($seconds % 60); $time = trans('activities.like') . ' '; if ($seconds < 60) { $time .= $secs . " " . $this->renderPostfixAgo($secs, 'second'); } else { if ($seconds < 60 * 60) { $time .= $mins . " " . $this->renderPostfixAgo($mins, 'minute'); } else { if ($seconds < 60 * 60 * 60) { $time .= $hours . " " . $this->renderPostfixAgo($hours, 'hour'); } else { if ($seconds < 24 * 60 * 60 * 60) { $time .= $day . " " . $this->renderPostfixAgo($day, 'day'); } else { if ($seconds < 24 * 60 * 60 * 60 * 30) { $time .= $months . " " . $this->renderPostfixAgo($months, 'month'); } else { $time .= $months . " " . $this->renderPostfixAgo($secs, 'year'); } } } } } return $time; }