Formatter for human-readable time
Only handles time up to 60 minutes gracefully

@param double  $time
@param integer $percision
@return string
3423
protected function getReadableTime($time, $percision = 3)
    {
        $unit = 's';
        if ($time < 1) {
            $time *= 1000;
            $percision = 0;
            $unit = 'ms';
        } elseif ($time > 60) {
            $time /= 60;
            $unit = 'm';
        }
        $time = number_format($time, $percision);
        return "{$time} {$unit}";
    }
1135107
private function parseTime($time)
    {
        $timezone = $this->config->get('app.timezone', 'UTC');

        /** @var Carbon $now */
        $now = Carbon::now($timezone);

        if (is_object($time)) {
            $deliveryTime = Carbon::instance($time);
        } else {
            if (is_array($time)) {
                reset($time);
                $type = key($time);
                $amount = $time[$type];
            } else {
                $type = 'seconds';
                $amount = $time;
            }

            /** @var Carbon $deliveryTime */
            $deliveryTime = Carbon::now($timezone);

            switch ($type) {
                case 'seconds':
                    $deliveryTime->addSeconds($amount);
                    break;
                case 'minutes':
                    $deliveryTime->addMinutes($amount);
                    break;
                case 'hours':
                    $deliveryTime->addHours($amount);
                    break;
                case 'days':
                    $deliveryTime->addHours($amount * 24);
                    break;
                default:
                    $deliveryTime->addSeconds($amount);
                    break;
            }
        }

        //Calculate boundaries
        $max = Carbon::now()->addHours(3 * 24);
        if ($deliveryTime->gt($max)) {
            $deliveryTime = $max;
        } elseif ($deliveryTime->lt($now)) {
            $deliveryTime = $now;
        }

        return $deliveryTime->format(\DateTime::RFC2822);
    }
957168
public function dateTimeString(string $time): string
    {
        return date($this->dateTimeFormat, ctype_digit($time) ? $time : strtotime($time));
    }
44124
private function duration($time){
        if(is_numeric($time)){ 
            return $time;
        }//if
        return (new \DateTime($time))->getTimestamp() - (new \DateTime('now'))->getTimestamp();
    }
677008
static public function microTime($isFormat = true)
    {
        if ($isFormat) {
            list($microSec, $sec) = explode(" ", microtime());
            return Format::datetime($sec) . ' ' . substr($microSec, 2, 6);
        } else {
            return microtime(true);
        }
    }
1163557
public static function timestamp($time = null): int
    {
        if ($time instanceof \DateTime) {
            return $time->format('U');
        }

        $time = time();

        if ($time !== null) {
            $time = is_numeric($time) ? (int) $time : strtotime($time);
        }

        return $time;
    }
850734
public function formatTime($time)
    {
        if ($this->timeFormat === null || $this->timeFormat === false) {
            return $time;
        }

        $dateTime = new \DateTime($time);

        if ($this->timeFormat === true) {
            return $dateTime;
        }

        return $dateTime->format($this->timeFormat);
    }
1362447
public function time(DateTimeInterface $dateTime, string $dateFormat = 'Y-m-d, H:i', string $clockFormat = ', H:i'): string
	{
		$diff = time() - $dateTime->getTimestamp();

		if($diff < 0)
		{
			// Our date is in the future

			$diff = abs($diff);

			if($diff < 120)
			{
				return $this->i18n->get('humanizer.in_minute');
			}
			elseif($diff < 3600)
			{
				return $this->i18n->get('humanizer.in_minutes', [$diff / 60]);
			}
			elseif($dateTime->format('Y-m-d') === date('Y-m-d'))
			{
				return $this->i18n->get('humanizer.today') . (!empty($clockFormat) ? $dateTime->format($clockFormat) : '');
			}
			elseif($dateTime->format('Y-m-d') === date('Y-m-d', time() + (60 * 60 * 24)))
			{
				return $this->i18n->get('humanizer.tomorrow') . (!empty($clockFormat) ? $dateTime->format($clockFormat) : '');
			}
		}
		else
		{
			// Our date is in the past

			if($diff < 120)
			{
				return $this->i18n->get('humanizer.minute_ago');
			}
			elseif($diff < 3600)
			{
				return $this->i18n->get('humanizer.minutes_ago', [$diff / 60]);
			}
			elseif($dateTime->format('Y-m-d') === date('Y-m-d'))
			{
				return $this->i18n->get('humanizer.today') . (!empty($clockFormat) ? $dateTime->format($clockFormat) : '');
			}
			elseif($dateTime->format('Y-m-d') === date('Y-m-d', time() - (60 * 60 * 24)))
			{
				return $this->i18n->get('humanizer.yesterday') . (!empty($clockFormat) ? $dateTime->format($clockFormat) : '');
			}
		}

		// None of the above so just return the default date format

		return $dateTime->format($dateFormat);
	}
855573
public function timeString(string $time): string
    {
        return date($this->timeFormat, ctype_digit($time) ? $time : strtotime($time));
    }
48389
public static function timeStamp($time)
    {
        $different = time() - $time;

        $seconds = $different;
        $minutes = round($different / 60);
        $hours = round($different / 3600);
        $days = round($different / 86400);
        $weeks = round($different / 604800);
        $months = round($different / 2419200);
        $years = round($different / 29030400);

        //Second
        if ($seconds <= 60) {
            if ($seconds == 1) {
                return "$seconds second ago";
            } else {
                return "$seconds seconds ago";
            }
        }

        //Minutes
        elseif ($minutes <= 60) {
            if ($minutes == 1) {
                return "$minutes minute ago";
            } else {
                return "$minutes minutes ago";
            }
        }

        //Hours
        elseif ($hours <= 24) {
            if ($hours == 1) {
                return "$hours hour ago";
            } else {
                return "$hours hours ago";
            }
        }

        //Days
        elseif ($days <= 7) {
            if ($days = 1) {
                return "$days day ago";
            } else {
                return "$days days ago";
            }
        }

        //Weeks
        elseif ($weeks <= 4) {
            if ($weeks == 1) {
                return "$weeks week ago";
            } else {
                return "$weeks weeks ago";
            }
        }

        //Months
        elseif ($months <= 12) {
            if ($months == 1) {
                return "$months month ago";
            } else {
                return "$months months ago";
            }
        }

        //Years
        else {
            if ($years == 1) {
                return "$years year ago";
            } else {
                return "$years years ago";
            }
        }
    }
1034841
public function humanAverageReadingTime($content)
    {
        if (empty($content)) {
            return '';
        }
        $content = StringHelper::stripHtml($content);
        $seconds = $this->averageReadingTime($content);

        return Craft::$app->formatter->asDuration($seconds);
    }
1237508
public function friendlyTime($time)
    {
        $time = $this->formatTime($time);
        (int) $s = 60;
        (int) $hour = $s * $s;
        (int) $day = $hour * 24;
        (int) $week = $day * 7;
        (int) $month = $day * 30;
        (int) $year = $month * 12;
        if ($time <= 60) {
            $ago = ($time === 0 || $time === 1) ? printl('z:format:just:now') : sprintf(printl('z:format:secs'), $time).' '.printl('z:format:ago');
        } elseif ($time >= $s && $time < $hour) {
            $ago = (round($time / $s) === 1) ? '1 '.printl('z:format:min').' '.printl('z:format:ago') : sprintf(printl('z:format:mints'), round($time / $s)).' '.printl('z:format:ago');
        } elseif ($time >= $hour && $time < $day) {
            $ago = (round($time / $hour) === 1) ? '1 '.printl('z:format:hour').' '.printl('z:format:ago') : sprintf(printl('z:format:hours'), round($time / $hour)).' '.printl('z:format:ago');
        } elseif ($time >= $day && $time < $week) {
            $ago = (round($time / $day) === 1) ? '1 '.printl('z:format:day').' '.printl('z:format:ago') : sprintf(printl('z:format:days'), round($time / $day)).' '.printl('z:format:ago');
        } elseif ($time >= $week && $time < $month) {
            $ago = (round($time / $week) === 1) ? '1 '.printl('z:format:week').' '.printl('z:format:ago') : sprintf(printl('z:format:weeks'), round($time / $week)).' '.printl('z:format:ago');
        } elseif ($time >= $month && $time < $year) {
            $ago = (round($time / $month) === 1) ? '1 '.printl('z:format:month').' '.printl('z:format:ago') : sprintf(printl('z:format:months'), round($time / $month)).' '.printl('z:format:ago');
        } elseif ($time >= $month) {
            $ago = (round($time / $month) === 1) ? '1 '.printl('z:format:year').' '.printl('z:format:ago') : sprintf(printl('z:format:years'), round($time / $year)).' '.printl('z:format:ago');
        }

        return $ago;
    }
795949
public static function toReadableTime($time, $decimals = 3)
    {
        $decimals = (int) $decimals;
        $unit     = 'sec';

        return sprintf("%.{$decimals}f %s", $time, $unit);
    }
76981
protected function formatTime($time)
    {
        if ($time > 100) {
            $time /= 60;
            if ($time > 100) {
                $time /= 60;

                return number_format($time) . " hr";
            }

            return number_format($time) . " min";
        }

        return number_format($time) . " sec";
    }
900657
public function getDuration($precision = 0, $floatingPrecision = 3, $showUnit = true)
    {
        if (empty($this->endTime)) {
            $this->stop();
        }

        return $this->getFormattedTime($this->endTime - $this->startTime, $precision, $floatingPrecision, $showUnit);
    }
1363921
public static function timetoDuration($time)
    {
        $duration = 'PT';

        $regexp = "/^([0-9]{2}):([0-9]{2}):([0-9]{2})(\.[0-9]{1,6})?$/";

        if (preg_match($regexp, $time, $matches)) {
            $duration .= intval($matches[1]) . 'H' . intval($matches[2]) . 'M';
            $duration .= isset($matches[4])
                ? intval($matches[3]) . $matches[4] . 'S'
                : intval($matches[3]) . 'S';
        } else {
            $duration .= '0S';
        }

        return $duration;
    }
370305
public function time($time, $precision = 0)
    {
        $units = 's';
        if ($time < 1e-6) {    // <1us
            $units = 'ns';
            $time *= 1e9;

        } elseif ($time < 1e-3) { // <1ms
            $units = "\xc2\xb5s";
            $time *= 1e6;

        } elseif ($time < 1) { // <1s
            $units = 'ms';
            $time *= 1e3;
        }

        return \round($time, $precision) . ' ' . $units;
    }