Backend\Modules\FormBuilder\Engine\Model::calculateTimeAgo PHP Method

calculateTimeAgo() public static method

Calculate time ago.
public static calculateTimeAgo ( integer $timestamp ) : string
$timestamp integer Unix timestamp from the past.
return string
    public static function calculateTimeAgo($timestamp)
    {
        $secondsBetween = time() - $timestamp;
        // calculate
        $hours = floor($secondsBetween / (60 * 60));
        $minutes = floor($secondsBetween / 60);
        $seconds = floor($secondsBetween);
        // today start
        $todayStart = (int) strtotime(date('d F Y'));
        // today
        if ($timestamp >= $todayStart) {
            // today
            if ($hours >= 1) {
                return BL::getLabel('Today') . ' ' . date('H:i', $timestamp);
            } elseif ($minutes > 1) {
                // more than one minute
                return sprintf(BL::getLabel('MinutesAgo'), $minutes);
            } elseif ($minutes == 1) {
                // one minute
                return BL::getLabel('OneMinuteAgo');
            } elseif ($seconds > 1) {
                // more than one second
                return sprintf(BL::getLabel('SecondsAgo'), $seconds);
            } elseif ($seconds <= 1) {
                // one second
                return BL::getLabel('OneSecondAgo');
            }
        } elseif ($timestamp < $todayStart && $timestamp >= $todayStart - 86400) {
            // yesterday
            return BL::getLabel('Yesterday') . ' ' . date('H:i', $timestamp);
        } else {
            // older
            return date('d/m/Y H:i', $timestamp);
        }
    }