public static function humanize($raw)
    {
        // convert to timestamp
        $timestamp = $raw;
        // raw can be instance of eloquent active record object, convert to str
        if (!Any::isInt($raw)) {
            $timestamp = self::convertToTimestamp((string)$timestamp);
        }

        // calculate difference between tomorrow day midnight and passed date
        $diff = time() - $timestamp;

        // date in future, lets return as is
        if ($diff < 0) {
            return self::convertToDatetime($timestamp, static::FORMAT_TO_SECONDS);
        }

        // calculate delta and make offset sub. Maybe usage instance of Datetime is better, but localization is sucks!
        $deltaSec = $diff % 60;
        $diff /= 60;

        $deltaMin = $diff % 60;
        $diff /= 60;

        $deltaHour = $diff % 24;
        $diff /= 24;

        $deltaDays = ($diff > 1) ? (int)floor($diff) : (int)$diff;

        // sounds like more then 1 day's ago
        if ($deltaDays > 1) {
            // sounds like more then 2 week ago, just return as is
            if ($deltaDays > 14) {
                return self::convertToDatetime($timestamp, static::FORMAT_TO_HOUR);
            }

            return App::$Translate->get('DateHuman', '%days% days ago', ['days' => (int)$deltaDays]);
        }

        // sounds like yesterday
        if ($deltaDays === 1) {
            return App::$Translate->get('DateHuman', 'Yestarday, %hi%', ['hi' => self::convertToDatetime($timestamp, 'H:i')]);
        }

        // sounds like today, more then 1 hour ago
        if ($deltaHour >= 1) {
            return App::$Translate->get('DateHuman', '%h% hours ago', ['h' => $deltaHour]);
        }

        // sounds like last hour ago
        if ($deltaMin >= 1) {
            return App::$Translate->get('DateHuman', '%m% minutes ago', ['m' => $deltaMin]);
        }

        // just few seconds left, lets return it
        return App::$Translate->get('DateHuman', '%s% seconds ago', ['s' => $deltaSec]);
    }
public static function humanize($raw)
    {
        // convert to timestamp
        $timestamp = $raw;
        // raw can be instance of eloquent active record object, convert to str
        if (!Any::isInt($raw)) {
            $timestamp = self::convertToTimestamp((string)$timestamp);
        }

        // calculate difference between tomorrow day midnight and passed date
        $diff = time() - $timestamp;

        // date in future, lets return as is
        if ($diff < 0) {
            return self::convertToDatetime($timestamp, static::FORMAT_TO_SECONDS);
        }

        // calculate delta and make offset sub. Maybe usage instance of Datetime is better, but localization is sucks!
        $deltaSec = $diff % 60;
        $diff /= 60;

        $deltaMin = $diff % 60;
        $diff /= 60;

        $deltaHour = $diff % 24;
        $diff /= 24;

        $deltaDays = ($diff > 1) ? (int)floor($diff) : (int)$diff;

        // sounds like more then 1 day's ago
        if ($deltaDays > 1) {
            // sounds like more then 2 week ago, just return as is
            if ($deltaDays > 14) {
                return self::convertToDatetime($timestamp, static::FORMAT_TO_HOUR);
            }

            return App::$Translate->get('DateHuman', '%days% days ago', ['days' => (int)$deltaDays]);
        }

        // sounds like yesterday
        if ($deltaDays === 1) {
            return App::$Translate->get('DateHuman', 'Yestarday, %hi%', ['hi' => self::convertToDatetime($timestamp, 'H:i')]);
        }

        // sounds like today, more then 1 hour ago
        if ($deltaHour >= 1) {
            return App::$Translate->get('DateHuman', '%h% hours ago', ['h' => $deltaHour]);
        }

        // sounds like last hour ago
        if ($deltaMin >= 1) {
            return App::$Translate->get('DateHuman', '%m% minutes ago', ['m' => $deltaMin]);
        }

        // just few seconds left, lets return it
        return App::$Translate->get('DateHuman', '%s% seconds ago', ['s' => $deltaSec]);
    }
public static function humanize ( $ raw ) { // convert to timestamp $ timestamp = $ raw ; // raw can be instance of eloquent active record object, convert to str if ( ! Any :: isInt ( $ raw ) ) { $ timestamp = self :: convertToTimestamp ( ( string ) $ timestamp ) ; } // calculate difference between tomorrow day midnight and passed date $ diff = time ( ) - $ timestamp ; // date in future, lets return as is if ( $ diff < 0 ) { return self :: convertToDatetime ( $ timestamp , static :: FORMAT_TO_SECONDS ) ; } // calculate delta and make offset sub. Maybe usage instance of Datetime is better, but localization is sucks! $ deltaSec = $ diff % 60 ; $ diff /= 60 ; $ deltaMin = $ diff % 60 ; $ diff /= 60 ; $ deltaHour = $ diff % 24 ; $ diff /= 24 ; $ deltaDays = ( $ diff > 1 ) ? ( int ) floor ( $ diff ) : ( int ) $ diff ; // sounds like more then 1 day's ago if ( $ deltaDays > 1 ) { // sounds like more then 2 week ago, just return as is if ( $ deltaDays > 14 ) { return self :: convertToDatetime ( $ timestamp , static :: FORMAT_TO_HOUR ) ; } return App :: $ Translate -> get ( 'DateHuman' , '%days% days ago' , [ 'days' => ( int ) $ deltaDays ] ) ; } // sounds like yesterday if ( $ deltaDays === 1 ) { return App :: $ Translate -> get ( 'DateHuman' , 'Yestarday, %hi%' , [ 'hi' => self :: convertToDatetime ( $ timestamp , 'H:i' ) ] ) ; } // sounds like today, more then 1 hour ago if ( $ deltaHour >= 1 ) { return App :: $ Translate -> get ( 'DateHuman' , '%h% hours ago' , [ 'h' => $ deltaHour ] ) ; } // sounds like last hour ago if ( $ deltaMin >= 1 ) { return App :: $ Translate -> get ( 'DateHuman' , '%m% minutes ago' , [ 'm' => $ deltaMin ] ) ; } // just few seconds left, lets return it return App :: $ Translate -> get ( 'DateHuman' , '%s% seconds ago' , [ 's' => $ deltaSec ] ) ; }
Humanize date format
@param string|int $raw
@return bool|string
Humanize date format