Pretty-prints the current time

@param $time
@return string
968833
protected static function formatTime($time) {
        if ($time > 1000 && $time < 60000) {
            return sprintf('%02.2f', $time / 1000).'s';
        }

        if ($time > 60000) {
            return sprintf('%02.2f', $time / 60000).'m';
        }

        return sprintf('%02.2f', $time).'ms';
    }
1202500
public function formatTimepoint($time, $format)
    {
        if ($time instanceof TimePoint) {
            return $time->format($format, $this->displayTimezone);
        }

        if ($time instanceof DateTime) {
            $formatted = clone $time;
            $formatted->setTimezone(new DateTimeZone($this->displayTimezone));
            return $formatted->format($format);
        }

        return '';
    }
247079
static function longTimeString($time) {
        str_replace('now', date('h:i:s t'), $time);

        if (!self::parsable($time)) return null;

        $r = self::fromString($time);

        return $r->format('h:i:s a');
    }
447924
protected function parseFloatTime($time)
	{
		$result = array();
		array_push($result, fmod($time, 60));
		$time = intval($time / 60);
		array_push($result, fmod($time, 60));
		$time = intval($time / 60);
		array_push($result, fmod($time, 60));
		return array_reverse($result);
	}
1008218
public static function strtotime($str, $time = null)
    {
        if (is_null($time)) {
            $time = self::time();
        }

        return strtotime($str, $time);
    }
1078591
public static function timeToSec($time)
    {
        // hh:mm:ss
        $split_time = explode(':', $time);
        $hour       = $split_time[0] * 3600;
        $minutes    = $split_time[1] * 60;
        $second     = $split_time[2] * 1;

        $timetosec = (int)($hour + $minutes + $second);

        return $timetosec;
    }
72334
private static function parseOneTime(string $time) : array
	{
		$time = static::translateToTimes($time);
		$parts = Strings::split($time, '/\s*-\s*/');
		if (!static::isValidTime($parts[0]) || (isset($parts[1]) && !static::isValidTime($parts[1]))) {
			throw new InvalidParameterException(
				"Times annotation is not in valid format. It must looks like 'hh:mm[ - hh:mm]' but '" . $time . "' was given."
			);
		}
		$times = [];
		if (static::isTimeOverMidnight($parts[0], isset($parts[1]) ? $parts[1] : NULL)) {
			$times[] = static::timePartsToArray('00:00', $parts[1]);
			$times[] = static::timePartsToArray($parts[0], '23:59');
		} else {
			$times[] = static::timePartsToArray($parts[0], isset($parts[1]) ? $parts[1] : NULL);
		}

		return $times;
	}
840499
public function timeTo(string $time): Date
    {
        $times = explode(':', $time);
        if (count($times) != 3) {
            throw new \InvalidArgumentException(
                    'Given time "' . $time . '" does not follow required format HH:MM:SS'
            );
        }

        list($hour, $minute, $second) = $times;
        if (!ctype_digit($hour) || 0 > $hour || 23 < $hour) {
            throw new \InvalidArgumentException(
                    'Given value ' . $hour . ' for hour not suitable for changing the time.'
            );
        }

        if (!ctype_digit($minute) || 0 > $minute || 59 < $minute) {
            throw new \InvalidArgumentException(
                    'Given value ' . $minute . ' for minute not suitable for changing the time.'
            );
        }

        if (!ctype_digit($second) || 0 > $second || 59 < $second) {
            throw new \InvalidArgumentException(
                    'Given value ' . $second . ' for second not suitable for changing the time.'
            );
        }

        return $this->createDateWithNewTime((int) $hour, (int) $minute, (int) $second);
    }
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;
    }
714735
protected function formatTimestamp(?int $time = null): string
    {
        if (empty($time)) {
            $time = time();
        }
        return gmdate('Y-m-d H:iO', $time);
    }
1304651
public static function toTimeString($time)
    {
        $times = array(
            'hour'   => 3600000,
            'minute' => 60000,
            'second' => 1000
        );

        $ms = $time;

        foreach ($times as $unit => $value) {
            if ($ms >= $value) {
                $time = floor($ms / $value * 100.0) / 100.0;
                return $time . ' ' . ($time == 1 ? $unit : $unit . 's');
            }
        }
        return $ms . ' ms';
    }
447880
protected function guessPattern($time) {
		$time = $this->latinizeDigits(trim($time));

		$shortDateRegex = '(\d{2,4})(-|\\\\|/)\d{1,2}\2\d{1,2}';
		$longDateRegex = '([^\d]*\s)?\d{1,2}(-| )[^-\s\d]+\4(\d{2,4})';
		$timeRegex = '\d{1,2}:\d{1,2}(:\d{1,2})?(\s.*)?';

		if (preg_match("@^(?:(?:$shortDateRegex)|(?:$longDateRegex))(\s+$timeRegex)?$@", $time, $match)) {
			if (!empty($match[1])) {
				$separator = $match[2];
				$pattern = strlen($match[1]) == 2 ? 'yy' : 'yyyy';
				$pattern .= $separator . 'MM' . $separator . 'dd';
			} else {
				$separator = $match[4];
				$pattern = 'dd' . $separator . 'LLL' . $separator;
				$pattern .= strlen($match[5]) == 2 ? 'yy' : 'yyyy';
				if (!empty($match[3])) $pattern = (preg_match('/,\s+$/', $match[3]) ? 'E, ' : 'E ') . $pattern;
			}
			if (!empty($match[6])) {
				$pattern .= !empty($match[8]) ? ' hh:mm' : ' HH:mm';
				if (!empty($match[7])) $pattern .= ':ss';
				if (!empty($match[8])) $pattern .= ' a';
			}
			return $pattern;
		}

		return false;
	}
1348625
protected function integerToString($time): string
    {
        $tokens = array_reverse($this->tokensValues, true);
        $expression = [];

        foreach ($tokens as $token => $value) {
            if ($time <= 0) {
                break;
            }
            if ($time < $value || !in_array($token, array_keys($this->tokensValues))) {
                continue;
            }
            $mod = 0;
            if ($time & $value) {
                $mod = fmod($time, $value);
                $time -= $mod;
            }
            $div = round($time / $value);

            $expression[] = sprintf(
                '%d %s',
                $div,
                ($token.(($div > 1 && substr($token, -1, 1) !== 's') ? 's' : ''))
            );
            $time = $mod;
        }

        $return = implode(' ', $expression);
        if (empty($return)) {
            $return = sprintf('%d %s', 0, 'ms');
        }

        return $return;
    }
964410
protected function ago($time)
    {
        $time = time() - $time;

        if ($time < 60) {
            return 'a moment ago';
        }

        $secs = array(
            'year'   => 365.25 * 24 * 60 * 60,
            'month'  => 30 * 24 * 60 * 60,
            'week'   => 7 * 24 * 60 * 60,
            'day'    => 24 * 60 * 60,
            'hour'   => 60 * 60,
            'minute' => 60,
        );

        foreach ($secs as $str => $s) {
            $d = $time / $s;

            if ($d >= 1) {
                $r = round($d);
                return sprintf('%d %s%s ago', $r, $str, ($r > 1) ? 's' : '');
            }
        }
    }
643305
public static function formatExcelTime($time, $format = '')
    {
        $time = \PHPExcel_Shared_Date::ExcelToPHP($time);
        if ($format) {
            $time = date($format, $time);
        }
        return $time;
    }
287307
protected function resolveTime($time)
    {
        $timestamp = strtotime($time);

        if ($timestamp !== false) {
            return $timestamp;
        }

        if ($time === 'this' || $time === 'thisMonth') {
            return strtotime('first day of this month midnight');
        }

        if ($time === 'prev' || $time === 'prevMonth') {
            return strtotime('first day of last month midnight');
        }

        return time();
    }
1195047
public function timeAgo($time = null, $format = null) {
		if (empty($time)) {
			$time = time();
		}
		if (empty($format)) {
			$format = '%x %X';
		}

		$result = $this->Html->tag(
			'time',
			$this->Time->i18nFormat($time, $format),
			[
				'data-toggle' => 'timeago',
				'datetime' => date('c', $this->Time->fromString($time)),
				'class' => 'help'
			]
		);

		return $result;
	}