/** * @param int $time * @param int|null $from * @return null|string */ public static function timeAgo($time, $from = NULL) { $from = DateTime::from($from); $time = DateTime::from($time); if ($from === NULL) { $from = time(); } $diff = $from->getTimestamp() - $time->getTimestamp(); if ($diff < 0) { return NULL; } $callback = self::$timeAgoCallback; if ($diff < 60) { return $callback('now', 0); } else { if ($diff < 3601) { return $callback('minutes', floor($diff / 60)); } else { if ($diff < 86401) { return $callback('hours', floor($diff / 3600)); } else { if ($diff < 2629801) { return $callback('days', floor($diff / 86400)); } else { if ($diff < 31536001) { return $callback('months', floor($diff / 2629800)); } else { return $callback('years', floor($diff / 31536000)); } } } } } }