kartik\helpers\Enum::time2String PHP Method

time2String() protected static method

Example Output: 1 year 5 months 3 days ago
protected static time2String ( integer $time, array $intervals ) : string
$time integer elapsed number of seconds
$intervals array configuration of time intervals in seconds
return string
    protected static function time2String($time, $intervals)
    {
        $output = '';
        foreach ($intervals as $name => $seconds) {
            $num = floor($time / $seconds);
            $time -= $num * $seconds;
            if ($num > 0) {
                $output .= $num . ' ' . $name . ($num > 1 ? 's' : '') . ' ';
            }
        }
        return trim($output);
    }