<commit_before><?php
namespace Kir\Services\Cmd\Dispatcher\Common;

use Exception;

class IntervalParser {
	/**
	 * @param string|int $interval
	 * @return int
	 */
	public static function parse($interval) {
		if(is_array($interval)) {
			$result = array();
			foreach($interval as $intervalStr) {
				$result[] = self::parseString($intervalStr);
			}
			return min($result);
		} else {
			return self::parseString((string) $interval);
		}
	}

	/**
	 * @param int|string $interval
	 * @return int
	 */
	private static function parseString($interval) {
		if(preg_match('/^\\d+$/', $interval)) {
			return $interval;
		}
		if(preg_match('/^(\\d{1,2}|\\*):(\\d{1,2}|\\*)(?::(\\d{1,2}|\\*))?$/', $interval, $matches)) {
			$matches[] = 0;
			list($hours, $minutes, $seconds) = array_slice($matches, 1);
			$possibleDates = [
				sprintf('today %02d:%02d:%02d', $hours, $minutes, $seconds),
				sprintf('tomorrow %02d:%02d:%02d', $hours, $minutes, $seconds),
			];
			return self::nearst($possibleDates);
		}
	}

	/**
	 * @param array $possibleDates
	 * @return int
	 * @throws Exception
	 */
	private static function nearst(array $possibleDates) {
		foreach($possibleDates as $possibleDate) {
			$time = strtotime($possibleDate);
			if($time > time()) {
				return $time - time();
			}
		}
		throw new Exception('No alternative lays in the future');
	}
}<commit_msg>- Throw an exception when the timeformat is not recognized<commit_after><?php
namespace Kir\Services\Cmd\Dispatcher\Common;

use Exception;

class IntervalParser {
	/**
	 * @param string|int $interval
	 * @return int
	 */
	public static function parse($interval) {
		if(is_array($interval)) {
			$result = array();
			foreach($interval as $intervalStr) {
				$result[] = self::parseString($intervalStr);
			}
			return min($result);
		} else {
			return self::parseString((string) $interval);
		}
	}

	/**
	 * @param int|string $interval
	 * @return int
	 * @throws Exception
	 */
	private static function parseString($interval) {
		if(preg_match('/^\\d+$/', $interval)) {
			return $interval;
		}
		if(preg_match('/^(\\d{1,2}|\\*):(\\d{1,2}|\\*)(?::(\\d{1,2}|\\*))?$/', $interval, $matches)) {
			$matches[] = 0;
			list($hours, $minutes, $seconds) = array_slice($matches, 1);
			$possibleDates = array(
				sprintf('today %02d:%02d:%02d', $hours, $minutes, $seconds),
				sprintf('tomorrow %02d:%02d:%02d', $hours, $minutes, $seconds),
			);
			return self::nearst($possibleDates);
		}
		throw new Exception("Unrecognized time format: {$interval}");
	}

	/**
	 * @param array $possibleDates
	 * @return int
	 * @throws Exception
	 */
	private static function nearst(array $possibleDates) {
		foreach($possibleDates as $possibleDate) {
			$time = strtotime($possibleDate);
			if($time > time()) {
				return $time - time();
			}
		}
		throw new Exception('No alternative lays in the future');
	}
}
{'fraction_non_alphanumeric': 0.193006993006993, 'fraction_numerical': 0.013986013986013986, 'mean_word_length': 3.8989726027397262, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6789306', 'n_tokens_mistral': 1127, 'n_tokens_neox': 961, 'n_words': 210}