Match agains pattern

@param string $time
@return array
546418
static protected function regex($time)
    {
      if(!preg_match('/^' . self::PATTERN . '$/', $time, $matches))
        throw new InvalidArgumentException(__METHOD__ . '; Invalid time, no match with pattern (' . $time . ')');
        
      return $matches;
    }
49056
public static function isValidTime($time)
    {
        if (preg_match('^(0|1|2)[0-9]([:](0|1|2|3|4|5)[0-9]){2}$', $time)) {
            $hour   = (int)substr($time, 0, 2);
            $minute = (int)substr($time, 3, 2);
            $second = (int)substr($time, 6, 2);
            if ($hour < 24 && $minute < 60 && $second < 60) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
855573
public function timeString(string $time): string
    {
        return date($this->timeFormat, ctype_digit($time) ? $time : strtotime($time));
    }
938712
public static function timestampToGmt($time = null)
    {
        $time = $time ?? time();
        $dateTime = new \DateTime();
        $dateTime->setTimestamp($time)->modify('+2 hours');

        return $dateTime->format('d/m/Y H:i:s');
    }
99823
protected function findReplacements($pattern)
    {
        if (0 !== strpos($pattern, '@')) {
            return $pattern;
        }

        $replace = [
            '@yearly'   => '0 0 1 1 * *',
            '@annually' => '0 0 1 1 * *',
            '@monthly'  => '0 0 1 * *',
            '@weekly'   => '0 0 * * 0',
            '@daily'    => '0 0 * * *',
            '@hourly'   => '0 * * * *',
        ];
        if (isset($replace[$pattern])) {
            $pattern = $replace[$pattern];
        }

        return $pattern;
    }
563377
public static function shortTime($time)
    {
        if (self::isTime($time)) {
            $str = self::dateTimeToTimeStamp($time);
            $string = date("H:i", $str);
            return $string;
        } else {
            return null;
        }
    }
818882
public function generateLock( $time ) {
		$theme = wp_get_theme();

		global $_wp_theme_features;
		$theme_features = is_array( $_wp_theme_features ) ? array_keys( $_wp_theme_features ) : [];

		$data = [
			'stylesheet' => get_stylesheet(),
			'name' => $theme->get( 'Name' ),
			'version' => $theme->get( 'Version' ),
			'timestamp' => $time,
			'features' => $theme_features,
		];
		$json = wp_json_encode( $data );
		$lockfile = $this->getLockDir() . '/lock.json';
		\Pressbooks\Utility\put_contents( $lockfile, $json );
		return $data;
	}
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);
    }
468540
public static function match($pattern, $event)
    {
        if (strpos($pattern, '*') === false) {
            return $event == $pattern;
        }

        $event   = explode('.', $event);
        $pattern = explode('.', $pattern);

        if (count($event) != ($count = count($pattern))) {
            return false;
        }

        for ($i = 0; $i < $count; $i++) {
            if ($pattern[$i] != '*' && $pattern[$i] != $event[$i]) {
                return false;
            }
        }

        return true;
    }
820664
private function matchesPattern($pattern) {
        $regexEncoding = mb_regex_encoding();
        mb_regex_encoding($this->encoding);

        $match = mb_ereg_match($pattern, $this->str);
        mb_regex_encoding($regexEncoding);

        return $match;
    }
278371
public static function wasLastMonth($time) {
        $start = static::factory('first day of last month 00:00:00');

        $end = clone $start;
        $end->modify('next month -1 second');

        $time = static::factory($time);

        return ($time >= $start && $time <= $end);
    }
548674
private function matchByRegex(string $pattern, string $path): array
    {
        $isPatternMatched = (bool) \preg_match_all("~^$pattern$~", $path, $matches);

        if (!$isPatternMatched) {
            return [$isPatternMatched, []];
        }

        foreach ($matches as $k => $match) {
            $match = \array_shift($match);
            if (\is_int($k) || empty($match)) {
                unset($matches[$k]);
                continue;
            }
            $matches[$k] = $match;
        }

        return [$isPatternMatched, $matches];
    }
999230
private function checkNameHour(string $time)
    {
        if (preg_match('/\s*\d{1,2}\s*(h|hour|hora|hs|hr|hrs)\s*/i', $time)) {
            $this->setCerteza("h", $time);
        }

        if (preg_match('/\s*\d{1,2}\s*(m|min|minuto)\s*/i', $time)) {
            $this->setCerteza("i", $time);
        }

        if (preg_match('/\s*\d{1,2}\s*(s|seg|segundo)\s*/i', $time)) {
            $this->setCerteza("s", $time);
        }
    }
466528
public function matchDateAndTimeAndZone($date, $time, $zone)
    {
        return $this->matchDate($date)
        && $this->matchTime($time)
        && $this->matchZone($zone);
    }
300403
public static function getDateTimes($time)
    {

        if (is_numeric($time)) {
            $intTime = $time;
        } else {
            $intTime = strtotime(strval($time));
            if ($intTime === false) {
                throw new \Exception("$time is invalid format");
            }
        }
        $res = date('c', $intTime);

        return substr($res, 0, 19);

    }
647112
public function validateDateTime($dateTime) {
        $return = [];

        if (!empty($dateTime)) {

            $escapedDateTime = str_replace(['  ', '   ', '    '], ' ', $dateTime);

            $aDateTime = explode(" ", $escapedDateTime);

            if (count($aDateTime) > 1) {
                $date = $aDateTime[0];
                $time = $aDateTime[1];

                $dateFormat = str_replace(['/', '-', '.'], '-', $date);

                if (preg_match('/^([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $dateFormat)) {
                    $format = 'Y-m-d';
                } else if (preg_match('/^(0[1-9]|[1-2][0-9]|3[0-1])-(0[1-9]|1[0-2])-([0-9]{4})$/', $dateFormat)) {
                    $format = 'd-m-Y';
                } else if (preg_match('/^(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])-([0-9]{4})$/', $dateFormat)) {
                    $format = 'm-d-Y';
                } else {
                    $format = null;
                }

                $return['date'] = $this->validateDate($dateFormat, $format);
                $return['time'] = $this->validateTime($time);
            } else {
                $return['date'] = false;
                $return['time'] = false;
            }
        } else {
            $return['date'] = false;
            $return['time'] = false;
        }

        if ($return['date'] and $return['time']) {
            $return['datetime'] = true;
        } else {
            $return['datetime'] = false;
        }

        return $return;
    }
155213
protected function _getUTCDate($time = null)
    {
        if ($time instanceof DateTimeInterface) {
            $result = clone $time;
        } elseif (is_int($time)) {
            $result = new DateTime(date('Y-m-d H:i:s', $time));
        } else {
            $result = new DateTime($time);
        }

        return $result->setTimezone(new DateTimeZone('UTC'));
    }