From bd775bec4572127554ca963437721a965bbec1e3 Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Tue, 16 Apr 2024 23:21:34 +0200 Subject: [PATCH] Refactor time splitter, support computing of dates for time entries --- src/NodaConsolidatedNamesForPersinst.php | 10 +- src/NodaCountingTimeIndicator.php | 74 +++ src/NodaSplitTime.php | 366 +++++++++++++ src/NodaTimeAutotranslater.php | 20 +- src/NodaTimeBeforeAfterIndicator.php | 67 +++ src/NodaTimeSplitter.php | 632 ++++++++++------------- tests/NodaTimeSplitterTest.php | 371 +++++++------ 7 files changed, 1006 insertions(+), 534 deletions(-) create mode 100644 src/NodaCountingTimeIndicator.php create mode 100644 src/NodaSplitTime.php create mode 100644 src/NodaTimeBeforeAfterIndicator.php diff --git a/src/NodaConsolidatedNamesForPersinst.php b/src/NodaConsolidatedNamesForPersinst.php index fa90923..da1606c 100644 --- a/src/NodaConsolidatedNamesForPersinst.php +++ b/src/NodaConsolidatedNamesForPersinst.php @@ -82,14 +82,14 @@ final class NodaConsolidatedNamesForPersinst extends NodaConsolidatedNamesAbstra $dateString = rtrim($parts[1], ')'); // if (!empty($dates = NodaTimeSplitter::is_timespan($dateString)) - && $dates[0] !== '?' - && $dates[1] !== '?' - && intval($dates[1]) - intval($dates[0]) < 150 + && $dates->start_year !== '?' + && $dates->end_year !== '?' + && intval($dates->end_year) - intval($dates->start_year) < 150 ) { return [ 'name' => $nameOnly, - 'birth' => $dates[0], - 'death' => $dates[1], + 'birth' => $dates->start_year, + 'death' => $dates->end_year, ]; } diff --git a/src/NodaCountingTimeIndicator.php b/src/NodaCountingTimeIndicator.php new file mode 100644 index 0000000..62eb308 --- /dev/null +++ b/src/NodaCountingTimeIndicator.php @@ -0,0 +1,74 @@ + + */ +declare(strict_types = 1); + +/** + * Represents a time indicator (CE / BCE). + */ +enum NodaCountingTimeIndicator implements JsonSerializable { + + case ce; + case bce; + + /** + * Returns a value of this type based on a string. + * + * @param string $input Input to get a value from. + * + * @return NodaCountingTimeIndicator + */ + public static function fromString(string $input):NodaCountingTimeIndicator { + + return match($input) { + '+' => self::ce, + '-' => self::bce, + 'ce' => self::ce, + 'bce' => self::bce, + default => throw new MDpageParameterNotFromListException("Unknown counting time indicator (bc / bce)"), + }; + + } + + /** + * Returns a canonical string representation. + * + * @return string + */ + public function toString():string { + + return match($this) { + self::ce => '+', + self::bce => '-', + }; + + } + + /** + * Returns a canonical string representation. + * + * @return string + */ + public function toGerman():string { + + return match($this) { + self::ce => ' n. Chr.', + self::bce => ' v. Chr.', + }; + + } + + /** + * Provides the option to serialize as a string during json_encode(). + * + * @return string + */ + public function jsonSerialize():string { + + return $this->toString(); + + } +} diff --git a/src/NodaSplitTime.php b/src/NodaSplitTime.php new file mode 100644 index 0000000..d773d03 --- /dev/null +++ b/src/NodaSplitTime.php @@ -0,0 +1,366 @@ + + */ +declare(strict_types = 1); + +/** + * Describes a time after splitting / transfer object. + */ +final class NodaSplitTime { + + const DEFAULT_DATE = '0001-01-01'; + + public readonly string $start_year; + public readonly string $end_year; + + public readonly string $counting_time_month; + public readonly string $counting_time_day; + + public readonly NodaCountingTimeIndicator $counting_time_indicator; + public readonly NodaTimeBeforeAfterIndicator $before_after_indicator; + + public string $start_date; + public string $end_date; + + /** + * Returns a single, exact date. + * + * @param string $year Year. + * @param string $month Month. + * @param string $day Day. + * + * @return NodaSplitTime + */ + public static function genExactDate(string $year, string $month, string $day, NodaTimeBeforeAfterIndicator $before_after_indicator = NodaTimeBeforeAfterIndicator::none):NodaSplitTime { + + $start_year = $end_year = $year; + $start_date = $end_date = $year . '-' . $month . '-' . $day; + + if ($before_after_indicator === NodaTimeBeforeAfterIndicator::before + || $before_after_indicator === NodaTimeBeforeAfterIndicator::until) { + $start_year = $start_date = '?'; + } + if ($before_after_indicator === NodaTimeBeforeAfterIndicator::after + || $before_after_indicator === NodaTimeBeforeAfterIndicator::since) { + $end_year = $end_date = '?'; + } + + return new NodaSplitTime($start_year, $end_year, $month, $day, start_date: $start_date, end_date: $end_date); + + } + + /** + * Validates the entered start year. + * + * @param string $input Input to validate. + * + * @return void + */ + private function _validateStartYear(string $input):void { + + if (strlen($input) > 6) { + throw new MDgenericInvalidInputsException("Time statement longer than 6 characters is impossible"); + } + + if (($this->before_after_indicator === NodaTimeBeforeAfterIndicator::before + || $this->before_after_indicator === NodaTimeBeforeAfterIndicator::until) + && $input !== '?' + ) { + throw new MDgenericInvalidInputsException("Times with no certain start need to have a question mark (?) entered as a start date"); + } + + } + + /** + * Validates the entered end year. + * + * @param string $input Input to validate. + * + * @return void + */ + private function _validateEndYear(string $input):void { + + if (strlen($input) > 6) { + throw new MDgenericInvalidInputsException("Time statement longer than 6 characters is impossible"); + } + + if (($this->before_after_indicator === NodaTimeBeforeAfterIndicator::after + || $this->before_after_indicator === NodaTimeBeforeAfterIndicator::since) + && $input !== '?' + ) { + throw new MDgenericInvalidInputsException("Times with no certain end need to have a question mark (?) entered as a end date"); + } + + + } + + /** + * Pads to four digits. E.g. 2 > 02. + * + * @param string $input Input string. + * + * @return string + */ + public static function pad_to_two(string $input):string { + + return \substr("00" . $input, -2); + + } + + /** + * Validates the entered month string. + * + * @param string $input Input to validate. + * + * @return string + */ + private function _validateCountingTimeMonth(string $input):string { + + if (strlen($input) > 2) throw new MDgenericInvalidInputsException("Input too long"); + + if ($input === '00') { + return $input; + } + + if (($parsedInt = filter_var(ltrim($input, "0"), FILTER_VALIDATE_INT)) === false) { + throw new MDgenericInvalidInputsException("Input value is not numeric"); + } + if ($parsedInt > 12) { + throw new MDgenericInvalidInputsException("Attempted to set a month number beyond 12"); + } + + return self::pad_to_two($input); + + } + + /** + * Validates the entered day string. + * + * @param string $input Input to validate. + * + * @return string + */ + private function _validateCountingTimeDay(string $input):string { + + if (strlen($input) > 2) throw new MDgenericInvalidInputsException("Input too long"); + + if ($input === '00') { + return $input; + } + + if (($parsedInt = filter_var(ltrim($input, "0"), FILTER_VALIDATE_INT)) === false) { + throw new MDgenericInvalidInputsException("Input value is not numeric"); + } + if ($parsedInt > 31) { + throw new MDgenericInvalidInputsException("Attempted to set a day number beyond 31"); + } + + return self::pad_to_two($input); + + } + + /** + * Returns a date time for the start of the time. + * + * @return DateTime + */ + public function startToDateTime():DateTime { + + if ($this->counting_time_indicator === NodaCountingTimeIndicator::bce) { + return new DateTime('-' . $this->start_date); + } + else { + return new DateTime($this->start_date); + } + + } + + /** + * Returns a date time for the end of the time. + * + * @return DateTime + */ + public function endToDateTime():DateTime { + + if ($this->counting_time_indicator === NodaCountingTimeIndicator::bce) { + return new DateTime('-' . $this->end_date); + } + else { + return new DateTime($this->end_date); + } + + } + + /** + * Generates a time name based on the current entry. + * + * @return string + */ + public function toTimeName():string { + + $prefix = $this->before_after_indicator->toString(); + if (!empty($prefix)) $prefix .= ' '; + + // Determine start and end for display + if ($this->start_year === '?') { + $start = (int)$this->end_year; + } + else $start = (int)$this->start_year; + + if ($this->end_year === '?') { + $end = (int)$this->start_year; + } + else $end = (int)$this->end_year; + + if ($this->before_after_indicator === NodaTimeBeforeAfterIndicator::before && $this->counting_time_month === '00') { + $start++; + $end++; + } + else if ($this->before_after_indicator === NodaTimeBeforeAfterIndicator::after && $this->counting_time_month === '00') { + $start--; + $end--; + } + + // Determine suffix + if ($start < 0 && $end < 0) { + $suffix = " v. Chr."; + } + else if ($end < 1000) { + $suffix = " n. Chr."; + } + else $suffix = ""; + + $start = \abs($start); + $end = \abs($end); + + if ($start !== $end) { + return "{$prefix}{$start}-{$end}{$suffix}"; + } + + // A single day of a given month of a given (single) year + else if (\intval($this->counting_time_month) !== 0 and \intval($this->counting_time_day) !== 0) { + return "{$prefix}{$this->counting_time_day}.{$this->counting_time_month}.{$start}{$suffix}"; + } + + // A single year + else if ($start === $end && trim((string)$this->counting_time_month, " 0") === "" && trim((string)$this->counting_time_day, " 0") === "") { + return "{$prefix}{$start}{$suffix}"; + } + + // Single month of a given year + else if ($start === $end && trim((string)$this->counting_time_month, " 0") !== "" && trim((string)$this->counting_time_day, " 0") === "") { + + $fmt = new IntlDateFormatter( + 'de-DE', + IntlDateFormatter::FULL, + IntlDateFormatter::FULL, + null, + IntlDateFormatter::GREGORIAN, + 'MMMM Y' + ); + + try { + return $prefix . $fmt->format(MD_STD::strtotime("{$start}-{$this->counting_time_month}-15 01:01:01")) . $suffix; + } + catch (MDInvalidInputDate $e) { + return ""; + } + } + + return ""; + + + } + + /** + * Returns an array in the old time splitter format (array with sex values). + * + * @return array + */ + public function toOldFormat():array { + + return [ + $this->start_year, + $this->end_year, + $this->counting_time_month, + $this->counting_time_day, + $this->counting_time_indicator->toString(), + $this->before_after_indicator->toString(), + ]; + + } + + /** + * Constructor. + * + * @return void + */ + public function __construct(string $start_year, string $end_year, + string $counting_time_month = "00", string $counting_time_day = "00", + NodaCountingTimeIndicator $counting_time_indicator = NodaCountingTimeIndicator::ce, + NodaTimeBeforeAfterIndicator $before_after_indicator = NodaTimeBeforeAfterIndicator::none, + false|string $start_date = false, + false|string $end_date = false, + ) { + + $this->counting_time_indicator = $counting_time_indicator; + $this->before_after_indicator = $before_after_indicator; + + $this->_validateStartYear($start_year); + $this->start_year = $start_year; + + $this->_validateEndYear($end_year); + $this->end_year = $end_year; + + $this->counting_time_month = $this->_validateCountingTimeMonth($counting_time_month); + $this->counting_time_day = $this->_validateCountingTimeDay($counting_time_day); + + // Calculate start date and end date + if (($this->before_after_indicator === NodaTimeBeforeAfterIndicator::before + || $this->before_after_indicator === NodaTimeBeforeAfterIndicator::until) + ) { + $this->start_date = '-9999-12-31'; + } + if (($this->before_after_indicator === NodaTimeBeforeAfterIndicator::after + || $this->before_after_indicator === NodaTimeBeforeAfterIndicator::since) + ) { + $this->end_date = '9999-12-31'; + } + + if (!isset($this->start_date) && false !== $start_date) { + $this->start_date = date("Y-m-d", MD_STD::strtotime($start_date)); + } + if (!isset($this->end_date) && false !== $end_date) { + $this->end_date = date("Y-m-d", MD_STD::strtotime($end_date)); + } + + if (!isset($this->start_date)) { + if ($this->counting_time_month === "00") { + $this->start_date = $this->start_year . '-01-01'; + } + else if ($this->counting_time_day === "00") { + $this->start_date = $this->start_year . '-' . $this->counting_time_month . '-01'; + } + else { + throw new MDgenericInvalidInputsException("Cannot identify start date automatically"); + } + } + if (!isset($this->end_date)) { + if ($this->counting_time_month === "00") { + $this->end_date = $this->end_year . '-12-31'; + } + else if ($this->counting_time_day === "00") { + $this->end_date = $this->end_year . '-' . $this->counting_time_month . '-31'; + } + else { + throw new MDgenericInvalidInputsException("Cannot identify end date automatically"); + } + } + + + } + +} diff --git a/src/NodaTimeAutotranslater.php b/src/NodaTimeAutotranslater.php index 0dcdea9..9ff6e74 100644 --- a/src/NodaTimeAutotranslater.php +++ b/src/NodaTimeAutotranslater.php @@ -480,12 +480,12 @@ final class NodaTimeAutotranslater { } $startTimeInfo = [ "zeit_name" => $timespanDates['start_name'], - "zeit_beginn" => $start[0], - "zeit_ende" => $start[1], + "zeit_beginn" => $start->start_year, + "zeit_ende" => $start->end_year, "zeit_zaehlzeit_jahr" => NodaTimeSplitter::timePartsToCountingYear($start), - "zeit_zaehlzeit_monat" => $start[2], - "zeit_zaehlzeit_tag" => $start[3], - "zeit_zaehlzeit_vorzeichen" => $start[4], + "zeit_zaehlzeit_monat" => $start->counting_time_month, + "zeit_zaehlzeit_tag" => $start->counting_time_day, + "zeit_zaehlzeit_vorzeichen" => $start->counting_time_indicator->toString(), ]; if (empty($end = NodaTimeSplitter::attempt_splitting($timespanDates['end_name']))) { @@ -493,12 +493,12 @@ final class NodaTimeAutotranslater { } $endTimeInfo = [ "zeit_name" => $timespanDates['end_name'], - "zeit_beginn" => $end[0], - "zeit_ende" => $end[1], + "zeit_beginn" => $end->start_year, + "zeit_ende" => $end->end_year, "zeit_zaehlzeit_jahr" => NodaTimeSplitter::timePartsToCountingYear($end), - "zeit_zaehlzeit_monat" => $end[2], - "zeit_zaehlzeit_tag" => $end[3], - "zeit_zaehlzeit_vorzeichen" => $end[4], + "zeit_zaehlzeit_monat" => $end->counting_time_month, + "zeit_zaehlzeit_tag" => $end->counting_time_day, + "zeit_zaehlzeit_vorzeichen" => $end->counting_time_indicator->toString(), ]; $output = []; diff --git a/src/NodaTimeBeforeAfterIndicator.php b/src/NodaTimeBeforeAfterIndicator.php new file mode 100644 index 0000000..ffcc7f5 --- /dev/null +++ b/src/NodaTimeBeforeAfterIndicator.php @@ -0,0 +1,67 @@ + + */ +declare(strict_types = 1); + +/** + * Represents a time indicator (CE / BCE). + */ +enum NodaTimeBeforeAfterIndicator implements JsonSerializable { + + case none; + case after; + case before; + case since; + case until; + + /** + * Returns a value of this type based on a string. + * + * @param string $input Input to get a value from. + * + * @return NodaTimeBeforeAfterIndicator + */ + public static function fromString(string $input):NodaTimeBeforeAfterIndicator { + + return match($input) { + '' => self::none, + 'Nach' => self::after, + 'Vor' => self::before, + 'Seit' => self::since, + 'Bis' => self::until, + default => throw new MDpageParameterNotFromListException("Unknown before / after indicator"), + }; + + } + + /** + * Returns a canonical string representation. + * + * @return string + */ + public function toString():string { + + return match($this) { + self::none => '', + self::after => 'Nach', + self::before => 'Vor', + self::since => 'Seit', + self::until => 'Bis', + }; + + } + + /** + * Provides the option to serialize as a string during json_encode(). + * + * @return string + */ + public function jsonSerialize():string { + + return $this->name; + + } +} diff --git a/src/NodaTimeSplitter.php b/src/NodaTimeSplitter.php index a2bfb81..16be366 100644 --- a/src/NodaTimeSplitter.php +++ b/src/NodaTimeSplitter.php @@ -209,111 +209,30 @@ final class NodaTimeSplitter { } - /** - * Generates new time name based on moda. - * - * @param array $moda Date strings. - * - * @return string - */ - public static function timePartsToTimeName(array $moda):string { - - if (!empty($moda[5]) and $moda[5] === "Vor" and $moda[0] === "?") { - if (empty(trim($moda[2], "0 "))) $moda[1] = \strval(\intval($moda[1]) + 1); - $moda[0] = $moda[1]; - $prefix = "Vor "; - } - else if (!empty($moda[5]) and $moda[5] === "Nach" and $moda[1] === "?") { - if (empty(trim($moda[2], "0 "))) $moda[0] = \strval(\intval($moda[0]) - 1); - $moda[1] = $moda[0]; - $prefix = "Nach "; - } - else if ($moda[0] === "?") { - $prefix = "Bis "; - $moda[0] = $moda[1]; - } - else if ($moda[1] === "?") { - $prefix = "Seit "; - $moda[1] = $moda[0]; - } - else $prefix = ""; - - $moda[0] = \intval($moda[0]); - $moda[1] = \intval($moda[1]); - - if ($moda[0] < 0 && $moda[1] < 0) { - $suffix = " v. Chr."; - } - else if ($moda[1] < 1000) { - $suffix = " n. Chr."; - } - else $suffix = ""; - - $moda[0] = \abs($moda[0]); - $moda[1] = \abs($moda[1]); - - if ($moda[0] !== $moda[1]) { - return "{$prefix}{$moda[0]}-{$moda[1]}{$suffix}"; - } - - // A single day of a given month of a given (single) year - else if (\intval($moda[2]) !== 0 and \intval($moda[3]) !== 0) { - return "{$prefix}{$moda[3]}.{$moda[2]}.{$moda[0]}{$suffix}"; - } - - // A single year - else if ($moda[0] === $moda[1] && trim((string)$moda[2], " 0") === "" && trim((string)$moda[3], " 0") === "") { - return "{$prefix}{$moda[0]}{$suffix}"; - } - - // Single month of a given year - else if ($moda[0] === $moda[1] && trim((string)$moda[2], " 0") !== "" && trim((string)$moda[3], " 0") === "") { - - $fmt = new IntlDateFormatter( - 'de-DE', - IntlDateFormatter::FULL, - IntlDateFormatter::FULL, - null, - IntlDateFormatter::GREGORIAN, - 'MMMM Y' - ); - - try { - return $prefix . $fmt->format(MD_STD::strtotime("{$moda[0]}-{$moda[2]}-15 01:01:01")) . $suffix; - } - catch (MDInvalidInputDate $e) { - return ""; - } - } - - return ""; - - } - /** * Generates counting year - the middle between start and end year. * - * @param array $moda Date strings. + * @param NodaSplitTime $moda Date strings. * * @return integer */ - public static function timePartsToCountingYear(array $moda):int { + public static function timePartsToCountingYear(NodaSplitTime $moda):int { - if ($moda[0] === "?") { - if (!empty($moda[5]) and $moda[5] === "Vor" and empty(trim($moda[2], " 0"))) { - return \abs(\intval($moda[1])) + 1; + if ($moda->start_year === "?") { + if ($moda->before_after_indicator === NodaTimeBeforeAfterIndicator::before and empty(trim($moda->counting_time_month, " 0"))) { + return \abs(\intval($moda->end_year)) + 1; } - return \abs(\intval($moda[1])); + return \abs(\intval($moda->end_year)); } - if ($moda[1] === "?") { - if (!empty($moda[5]) and $moda[5] === "Nach" and empty(trim($moda[2], " 0"))) { - return \abs(\intval($moda[0])) - 1; + if ($moda->end_year === "?") { + if ($moda->before_after_indicator === NodaTimeBeforeAfterIndicator::after and empty(trim($moda->counting_time_month, " 0"))) { + return \abs(\intval($moda->start_year)) - 1; } - return \abs(\intval($moda[0])); + return \abs(\intval($moda->start_year)); } - return \abs((int)\ceil(\intval($moda[1]) - ((\intval($moda[1]) - \intval($moda[0])) / 2))); + return \abs((int)\ceil(\intval($moda->end_year) - ((\intval($moda->end_year) - \intval($moda->start_year)) / 2))); } @@ -321,12 +240,12 @@ final class NodaTimeSplitter { * Generates HTML for linking disassembly of times for a single day. * * @param integer $znum Time ID. - * @param array $moda Date strings. + * @param NodaSplitTime $moda Date strings. * @param MDTlLoader $tlLoader Translation loader. * * @return string */ - public static function generateDisassemblyForDay(int $znum, array $moda, MDTlLoader $tlLoader):string { + public static function generateDisassemblyForDay(int $znum, NodaSplitTime $moda, MDTlLoader $tlLoader):string { $zaehlzeit_jahr = self::pad_to_four((string)self::timePartsToCountingYear($moda)); @@ -335,19 +254,19 @@ final class NodaTimeSplitter { $output .= ''; $output .= ''; $output .= ''; $output .= ''; @@ -406,44 +325,46 @@ final class NodaTimeSplitter { * * @param string $datum Date. * - * @return array{0: string, 1: string, 2: string, 3: string, 4: '+'|'-'|'', 5: string}|array{} + * @return NodaSplitTime|false */ - public static function is_valid_date(string $datum):array { + public static function is_valid_date(string $datum):NodaSplitTime|false { $datum = self::clean_input($datum); if (\str_ends_with($datum, ' v. Chr.')) { if ($output = self::attempt_splitting(\substr($datum, 0, -8))) { - $start = \strval(-1 * \intval($output[1])); - $end = \strval(-1 * \intval($output[0])); + + $start = \strval(-1 * \intval($output->end_year)); + $end = \strval(-1 * \intval($output->start_year)); if (\intval($start) > \intval($end)) { $startToSet = $end; $end = $start; $start = $startToSet; } - return [$start, $end, $output[2], $output[3], '-', ""]; + return new NodaSplitTime($start, $end, $output->counting_time_month, $output->counting_time_day, + NodaCountingTimeIndicator::bce, $output->before_after_indicator, '-' . $output->end_date, '-' . $output->start_date); } } if (\preg_match("/^[0-9][0-9][0-9][0-9]\ bis [0-9][0-9][0-9][0-9]$/", $datum)) { $start = \substr($datum, 0, 4); $end = \substr($datum, -4); - return [$start, $end, "00", "00", "+", ""]; + return new NodaSplitTime($start, $end); } $datum = \str_replace(". ", ".", $datum); if (self::stri_occurs($datum, self::STOP_STRINGS_GERMAN)) { - return []; + return false; } - if (strlen($datum) <= 6) return []; + if (strlen($datum) <= 6) return false; if (strlen($datum) <= 9) $use_day = false; else $use_day = true; if (self::is_numeric((string)\substr($datum, -4))) $year = \substr($datum, -4); // Further code requires a year to be present, skip if none is set - if (empty($year)) return []; + if (empty($year)) return false; foreach (self::MONTH_NAMES_ENGLISH as $monthVal => $monthValidNames) { if (self::stri_occurs($datum, $monthValidNames)) { @@ -469,12 +390,12 @@ final class NodaTimeSplitter { } if (!empty($monat) and !empty($day) and $use_day) { - return [$year, $year, $monat, $day, '+', ""]; + return NodaSplitTime::genExactDate($year, $monat, $day); } else if (!empty($monat)) { - return [$year, $year, $monat, "00", '+', ""]; + return new NodaSplitTime($year, $year, $monat); } - return []; + return false; } @@ -483,22 +404,23 @@ final class NodaTimeSplitter { * * @param string $datum Date. * - * @return array{0: string, 1: string, 2: string, 3: string, 4: '+'|'-'|'', 5: string}|array{} + * @return NodaSplitTime|false */ - public static function is_valid_date_hungarian(string $datum):array { + public static function is_valid_date_hungarian(string $datum):NodaSplitTime|false { $datum = self::clean_input($datum); if (\preg_match("/^Kr\.\ e\.\ /", $datum)) { if ($output = self::attempt_splitting(\substr($datum, 7))) { - $start = \strval(-1 * \intval($output[1])); - $end = \strval(-1 * \intval($output[0])); + $start = \strval(-1 * \intval($output->end_year)); + $end = \strval(-1 * \intval($output->start_year)); if (\intval($start) > \intval($end)) { $startToSet = $end; $end = $start; $start = $startToSet; } - return [$start, $end, $output[2], $output[3], '-', ""]; + return new NodaSplitTime($start, $end, $output->counting_time_month, $output->counting_time_day, + NodaCountingTimeIndicator::bce, $output->before_after_indicator, '-' . $output->end_date, '-' . $output->start_date); } } @@ -507,17 +429,17 @@ final class NodaTimeSplitter { if (\preg_match("/^[0-9][0-9][0-9][0-9]\-t(ő|ó)l(\ |\-)[0-9][0-9][0-9][0-9]\-ig$/", $datum)) { $start = \substr($datum, 0, 4); $end = \substr($datum, -7, 4); - return [$start, $end, "00", "00", "+", ""]; + return new NodaSplitTime($start, $end); } if (self::stri_occurs($datum, self::STOP_STRINGS_HUNGARIAN)) { - return []; + return false; } // // Rest: Only those entries, where there are spelled out months // - if (strlen($datum) <= 9) return []; + if (strlen($datum) <= 9) return false; // The year is only parse-able if it is a four digit year at the start if (self::is_numeric((string)\substr($datum, 0, 4)) && substr($datum, 4, 1) === '.') { @@ -525,10 +447,10 @@ final class NodaTimeSplitter { } // Further code requires a year to be present, skip if none is set - if (empty($year)) return []; + if (empty($year)) return false; // Skip, if dates are too long and do not contain spaces (= no translatable names) - if (str_contains($datum, " ") === false && strlen($datum) > 12) return []; + if (str_contains($datum, " ") === false && strlen($datum) > 12) return false; $unparsed = trim(strtolower(str_replace($year, '', $datum)), ' ,.'); foreach (self::MONTH_NAMES_HUNGARIAN as $monthVal => $monthValidNames) { @@ -542,7 +464,7 @@ final class NodaTimeSplitter { } if (strlen($unparsed) > 5) { - return []; + return false; } if (empty($monat) and self::is_numeric((string)\substr($datum, 5, 2))) $monat = \substr($datum, 5, 2); @@ -565,16 +487,16 @@ final class NodaTimeSplitter { } if (!empty($monat) && empty($day) && preg_match('~[0-9]+~', substr($datum, -3))) { - return []; + return false; } if (!empty($monat) and !empty($day)) { - return [$year, $year, $monat, $day, '+', ""]; + return NodaSplitTime::genExactDate($year, $monat, $day); } else if (!empty($monat)) { - return [$year, $year, $monat, "00", '+', ""]; + return new NodaSplitTime($year, $year, $monat); } - return []; + return false; } @@ -583,17 +505,17 @@ final class NodaTimeSplitter { * * @param string $datum Date. * - * @return array + * @return NodaSplitTime|false */ - public static function is_valid_date_by_php(string $datum):array { + public static function is_valid_date_by_php(string $datum):NodaSplitTime|false { $datum = self::clean_input($datum); if (!($timeInt = \strtotime($datum))) { - return []; + return false; } - return [\date("Y", $timeInt), \date("m", $timeInt), \date("d", $timeInt), '+', ""]; + return NodaSplitTime::genExactDate(\date("Y", $timeInt), \date("m", $timeInt), \date("d", $timeInt)); } @@ -602,166 +524,151 @@ final class NodaTimeSplitter { * * @param string $datum Input date. * - * @return array{0: string, 1: string, 2: string, 3: string, 4: '+'|'-'|'', 5: string}|array{} + * @return NodaSplitTime|false */ - public static function is_timespan(string $datum):array { + public static function is_timespan(string $datum):NodaSplitTime|false { $datum = self::clean_input($datum); // 10000-20000 if (!empty(\preg_match("/^[0-9]{5}(\-|\/)[0-9]{5}$/", $datum))) { - $start = \substr($datum, 0, 5); - $end = \substr($datum, 6, 5); - return [$start, $end, "00", "00", "+", ""]; + return new NodaSplitTime(start_year: \substr($datum, 0, 5), end_year: \substr($datum, 6, 5)); } // 0000-0000 if (\preg_match("/^[0-9]{4}(\-|\/)[0-9]{4}(\.|)$/", $datum)) { - $start = \substr($datum, 0, 4); - $end = \substr($datum, 5, 4); - return [$start, $end, "00", "00", "+", ""]; + return new NodaSplitTime(start_year: \substr($datum, 0, 4), end_year: \substr($datum, 5, 4)); } + // 1.900-2.000 if (\preg_match("/^[0-9]\.[0-9][0-9][0-9](\-|\/)[0-9]\.[0-9][0-9][0-9]$/", $datum)) { $datum = \str_replace(".", "", $datum); - $start = \substr($datum, 0, 4); - $end = \substr($datum, 5, 4); - return [$start, $end, "00", "00", "+", ""]; + return new NodaSplitTime(start_year: \substr($datum, 0, 4), end_year: \substr($datum, 5, 4)); } // German TT.MM.JJJJ / TT.MM.JJJ / TT.MM.JJ / TT.MM.J if (\preg_match("/^[0-9][0-9]\.[0-9][0-9]\.([0-9][0-9][0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9]|[0-9])$/", $datum)) { // German T.MM.JJJJ - $start = \substr($datum, 6, 4); + $year = \substr($datum, 6, 4); $month = \substr($datum, 3, 2); $day = \substr($datum, 0, 2); - return [$start, $start, $month, $day, "+", ""]; + return NodaSplitTime::genExactDate($year, $month, $day); } // German TT.M.JJJJ / TT.M.JJJ / TT.M.JJ / TT.M.J if (\preg_match("/^[0-9][0-9]\.[0-9]\.([0-9][0-9][0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9]|[0-9])$/", $datum)) { // German T.MM.JJJJ - $start = \substr($datum, 5, 4); + $year = \substr($datum, 5, 4); $month = "0" . \substr($datum, 3, 1); $day = \substr($datum, 0, 2); - return [$start, $start, $month, $day, "+", ""]; + return NodaSplitTime::genExactDate($year, $month, $day); } // German T.MM.JJJJ / T.MM.JJJ / T.MM.JJ / T.MM.J if (\preg_match("/^[0-9]\.[0-9][0-9]\.([0-9][0-9][0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9]|[0-9])$/", $datum)) { - $start = \substr($datum, 5, 4); + $year = \substr($datum, 5, 4); $month = \substr($datum, 2, 2); $day = "0" . \substr($datum, 0, 1); - return [$start, $start, $month, $day, "+", ""]; + return NodaSplitTime::genExactDate($year, $month, $day); } // German T.M.JJJJ / T.M.JJJ / T.M.JJ / T.M.J if (\preg_match("/^[0-9]\.[0-9]\.([0-9][0-9][0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9]|[0-9])$/", $datum)) { - $start = \substr($datum, 4, 4); + $year = \substr($datum, 4, 4); $month = "0" . \substr($datum, 2, 1); $day = "0" . \substr($datum, 0, 1); - return [$start, $start, $month, $day, "+", ""]; + return NodaSplitTime::genExactDate($year, $month, $day); } // Intl': 2020-12-20 if (\preg_match("/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$/", $datum)) { // German Y-m - $start = \substr($datum, 0, 4); + $year = \substr($datum, 0, 4); $month = \substr($datum, 5, 2); - if (\intval($month) < 13) { - $day = \substr($datum, 8, 2); - return [$start, $start, $month, $day, "+", ""]; - } - else { - unset($start, $month); - } + $day = \substr($datum, 8, 2); + return NodaSplitTime::genExactDate($year, $month, $day); } // Intl': 2020-12 if (\preg_match("/^[0-9]{4}\-[0-9]{2}$/", $datum)) { // German Y-m - $start = \substr($datum, 0, 4); + $year = \substr($datum, 0, 4); $month = \substr($datum, 5, 2); - if (\intval($month) < 13) { - return [$start, $start, $month, "00", "+", ""]; - } - else { - unset($start, $month); - } + return new NodaSplitTime($year, $year, $month); } // German MM.JJJJ if (\preg_match("/^[0-9]{2}\.[0-9]{4}$/", $datum)) { // German Y-m - $start = \substr($datum, 3, 4); + $year = \substr($datum, 3, 4); $month = \substr($datum, 0, 2); - return [$start, $start, $month, "00", "+", ""]; + return new NodaSplitTime($year, $year, $month); } if (\preg_match("/^[0-9]\.[0-9]{4}$/", $datum)) { // German Y-m - $start = \substr($datum, 2, 4); + $year = \substr($datum, 2, 4); $month = "0" . \substr($datum, 0, 1); - return [$start, $start, $month, "00", "+", ""]; + return new NodaSplitTime($year, $year, $month); } if (\preg_match("/^[0-9]{4}\.[0-3][0-9]\.[0-9]{1,2}(\.|)$/", $datum)) { // Hungarian Y-m-d - $start = \substr($datum, 0, 4); + $year = \substr($datum, 0, 4); $month = \substr($datum, 5, 2); $day = self::pad_to_two(\rtrim(\substr($datum, 8, 2), '.')); - if (\intval($month) < 13) return [$start, $start, $month, $day, "+", ""]; + return NodaSplitTime::genExactDate($year, $month, $day); } if (\preg_match("/^[0-9]{4}\.[0-9]\.[0-9]{1,2}\.$/", $datum)) { // Hungarian Y-m-d > 2005.1.1. - $start = \substr($datum, 0, 4); + $year = \substr($datum, 0, 4); $month = self::pad_to_two(\substr($datum, 5, 1)); $day = self::pad_to_two(\rtrim(\substr($datum, 7, 2), '.')); - if (\intval($month) < 13) return [$start, $start, $month, $day, "+", ""]; + return NodaSplitTime::genExactDate($year, $month, $day); } if (\preg_match("/^[0-9]{4}\.[0-3][0-9](\.|)$/", $datum)) { // Hungarian Y-m - $start = \substr($datum, 0, 4); + $year = \substr($datum, 0, 4); $month = \substr($datum, 5, 2); - if (\intval($month) < 13) return [$start, $start, $month, "00", "+", ""]; + return new NodaSplitTime($year, $year, $month); } if (\preg_match("/^[0-9]{4}\-[0-9]{2}$/", $datum)) { // Time spans: 1945-46 $start = \substr($datum, 0, 4); $endDigits = \substr($datum, 5, 2); - if (\intval($endDigits) > 12) return [$start, \substr($datum, 0, 2) . $endDigits, "00", "00", "+", ""]; + return new NodaSplitTime($start, \substr($datum, 0, 2) . $endDigits); } // 01.01.1920-31.12.1930 if (\preg_match("/^01\.01\.[0-9]{4}\-31\.12\.[0-9]{4}$/", $datum)) { // Hungarian Y-m $start = \substr($datum, 6, 4); $end = \substr($datum, -4); - return [$start, $end, "00", "00", "+", ""]; + return new NodaSplitTime($start, $end); } // 303-305 (n. Chr.) if (\preg_match("/^[0-9]{3}\-[0-9]{3}$/", $datum)) { // Hungarian Y-m $start = \substr($datum, 0, 3); $end = \substr($datum, -3); - return ["0" . $start, "0" . $end, "00", "00", "+", ""]; + return new NodaSplitTime("0" . $start, "0" . $end); } // 1720-120 if (\preg_match("/^[0-9]{4}\-[0-9]{3}$/", $datum)) { // Hungarian Y-m $start = \substr($datum, 0, 4); $end = \substr($datum, -3); - return ["0" . $start, "0" . $end, "00", "00", "+", ""]; + return new NodaSplitTime("0" . $start, "0" . $end); } // 20-30 (n. Chr.) if (\preg_match("/^[0-9]{2}\-[0-9]{2}$/", $datum)) { // 20-40 (n. Chr.) $start = \substr($datum, 0, 2); $end = \substr($datum, -2); - return ["00" . $start, "00" . $end, "00", "00", "+", ""]; + return new NodaSplitTime("00" . $start, "00" . $end); } // 1920 if (\preg_match("/^[0-9]{4}(\.|)$/", $datum)) { $start = \substr($datum, 0, 4); - return [$start, $start, "00", "00", "+", ""]; + return new NodaSplitTime($start, $start); } // 1920 if (\preg_match("/^[0-9]{3}$/", $datum)) { $start = "0" . \substr($datum, 0, 3); - return [$start, $start, "00", "00", "+", ""]; + return new NodaSplitTime($start, $start); } if (\preg_match("/^[0-9]{2}$/", $datum)) { $start = "00" . \substr($datum, 0, 2); - return [$start, $start, "00", "00", "+", ""]; + return new NodaSplitTime($start, $start); } // Special case for SMB: YYYY, MM. DD and YYYY, MM. @@ -769,11 +676,11 @@ final class NodaTimeSplitter { if (\preg_match("/^[0-9]{4}\,\ [0-9]{2}\.(|\ [0-9]{2})$/", $datum)) { $start = \substr($datum, 0, 4); $month = \substr($datum, 6, 2); - $day = self::pad_to_two(\substr($datum, 10, 2)); - return [$start, $start, $month, $day, "+", ""]; + $day = \substr($datum, 10, 2); + return NodaSplitTime::genExactDate($start, $month, $day); } - return []; + return false; } @@ -782,191 +689,166 @@ final class NodaTimeSplitter { * * @param string $datum Input date. * - * @return array{0: string, 1: string, 2: string, 3: string, 4: '+'|'-'|'', 5: string}|array{} + * @return NodaSplitTime|false */ - public static function is_incomplete_date(string $datum):array { + public static function is_incomplete_date(string $datum):NodaSplitTime|false { $datum = self::clean_input($datum); - if (\preg_match("/^[0-9]{4}\.[0-9]{2}\.[0-9]{2}(\.|)\-$/", $datum)) { // Hungarian Y-m - $start = \substr($datum, 0, 4); + if (\preg_match("/^[0-9]{4}\.[0-9]{2}\.[0-9]{2}(\.|)\-$/", $datum)) { // YYYY.MM.DD. + $year = \substr($datum, 0, 4); $month = \substr($datum, 5, 2); $day = \substr($datum, 8, 2); - return [$start, "?", $month, $day, "+", ""]; + return NodaSplitTime::genExactDate($year, $month, $day, NodaTimeBeforeAfterIndicator::since); } - if (\preg_match("/^[0-9]{4}\.[0-9]{2}(\.|)\-$/", $datum)) { // Hungarian Y-m + if (\preg_match("/^[0-9]{4}\.[0-9]{2}(\.|)\-$/", $datum)) { // YYYY.MM.- $start = \substr($datum, 0, 4); $month = \substr($datum, 5, 2); - return [$start, "?", $month, "00", "+", ""]; + return new NodaSplitTime($start, '?', $month, before_after_indicator: NodaTimeBeforeAfterIndicator::since); } - if (\preg_match("/^[0-9]{4}\-$/", $datum)) { // Hungarian Y- + if (\preg_match("/^[0-9]{4}\-$/", $datum)) { // YYYY- $start = \substr($datum, 0, 4); - return [$start, "?", "00", "00", "+", ""]; + return new NodaSplitTime($start, '?', before_after_indicator: NodaTimeBeforeAfterIndicator::since); } if (\preg_match("/^\-[0-9]{4}\.[0-9]{2}\.[0-9]{2}$/", $datum)) { // Hungarian Y-m - $start = \substr($datum, 1, 4); + $year = \substr($datum, 1, 4); $month = \substr($datum, 6, 2); $day = \substr($datum, 9, 2); - return ["?", $start, $month, $day, "+", ""]; + return NodaSplitTime::genExactDate($year, $month, $day, NodaTimeBeforeAfterIndicator::until); } if (\preg_match("/^\-[0-9]{4}\.[0-9]{2}$/", $datum)) { // Hungarian Y-m - $start = \substr($datum, 1, 4); + $year = \substr($datum, 1, 4); $month = \substr($datum, 6, 2); - return ["?", $start, $month, "00", "+", ""]; + return new NodaSplitTime('?', $year, $month, before_after_indicator: NodaTimeBeforeAfterIndicator::until); } if (\preg_match("/^\-[0-9]{4}$/", $datum)) { // Hungarian -Y - $start = \substr($datum, 1, 4); - return ["?", $start, "00", "00", "+", ""]; + $year = \substr($datum, 1, 4); + return new NodaSplitTime('?', $year, before_after_indicator: NodaTimeBeforeAfterIndicator::until); } if (\preg_match("/^(Nach|nach)\ /", $datum)) { if (($spacePos = \strpos($datum, " ")) === false) { - return []; + return false; } if ($output = self::attempt_splitting(\substr($datum, $spacePos))) { - - // Handle cases like "Nach 60er Jahre" with divergent start and end year - if ($output[1] !== $output[0] and \intval($output[1]) > \intval($output[0])) { - $output[0] = $output[1]; - } - - $output[1] = "?"; - if (empty(trim($output[2], "0 .,"))) $output[0] = \strval(\intval($output[0]) + 1); - $output[5] = "Nach"; - return $output; + return self::_turn_noda_split_time_to_after($output); } } if (\preg_match("/\ (\(nach|nach)$/", $datum)) { if (($spacePos = \strpos($datum, " ")) === false) { - return []; + return false; } if ($output = self::attempt_splitting(\substr($datum, 0, $spacePos))) { - - // Handle cases like "Nach 60er Jahre" with divergent start and end year - if ($output[1] !== $output[0] and \intval($output[1]) > \intval($output[0])) { - $output[0] = $output[1]; - } - - $output[1] = "?"; - if (empty(trim($output[2], "0 .,"))) $output[0] = \strval(\intval($output[0]) + 1); - $output[5] = "Nach"; - return $output; + return self::_turn_noda_split_time_to_after($output); } } if (\preg_match("/^(Vor|vor)\ /", $datum)) { if (($spacePos = \strpos($datum, " ")) === false) { - return []; + return false; } if ($output = self::attempt_splitting(\substr($datum, $spacePos))) { + return self::_turn_noda_split_time_to_before($output); - $output[0] = "?"; - if (empty(trim($output[2], "0 .,"))) $output[1] = \strval(\intval($output[1]) - 1); - $output[5] = "Vor"; - return $output; } } if (\preg_match("/\ (\(vor|\(Vor|vor|előtt)$/", $datum)) { if (($spacePos = \strrpos($datum, " ")) === false) { - return []; + return false; } if ($output = self::attempt_splitting(\substr($datum, 0, $spacePos))) { - - $output[0] = "?"; - // If month and day are unknown, lower end year by one - if (empty(trim($output[2], "0 .,"))) { - $output[1] = \strval(\intval($output[1]) - 1); - } - $output[5] = "Vor"; - return $output; + return self::_turn_noda_split_time_to_before($output); } } if (\preg_match("/^(Ab|ab|Seit|seit)\ /", $datum)) { if (($spacePos = \strpos($datum, " ")) === false) { - return []; + return false; } if ($output = self::attempt_splitting(\substr($datum, $spacePos))) { - $output[1] = "?"; - return $output; + + return new NodaSplitTime($output->start_year, '?', $output->counting_time_month, $output->counting_time_day, + $output->counting_time_indicator, NodaTimeBeforeAfterIndicator::since, $output->start_date, '?'); + } } // Endings beginning with a dash if (\preg_match("/(\-től|\-tól)$/", $datum)) { if (($spacePos = strrpos($datum, "-")) === false) { - return []; + return false; } if ($output = self::attempt_splitting(\substr($datum, 0, $spacePos))) { - $output[1] = "?"; - return $output; + + return new NodaSplitTime($output->start_year, '?', $output->counting_time_month, $output->counting_time_day, + $output->counting_time_indicator, NodaTimeBeforeAfterIndicator::since, $output->start_date, '?'); + } } if (\preg_match("/^(Bis|bis)\ /", $datum)) { if (($spacePos = \strpos($datum, " ")) === false) { - return []; + return false; } if ($output = self::attempt_splitting(\substr($datum, $spacePos))) { - $output[0] = "?"; - return $output; + return new NodaSplitTime('?', $output->end_year, $output->counting_time_month, $output->counting_time_day, + $output->counting_time_indicator, NodaTimeBeforeAfterIndicator::until, '?', $output->end_date); + } + } + // Endings beginning with a space (until) + if (\preg_match("/ (\(bis)$/", $datum)) { + if (($spacePos = strrpos($datum, " ")) === false) { + return false; + } + if ($output = self::attempt_splitting(\substr($datum, 0, $spacePos))) { + return new NodaSplitTime('?', $output->end_year, $output->counting_time_month, $output->counting_time_day, + $output->counting_time_indicator, NodaTimeBeforeAfterIndicator::until, '?', $output->end_date); + } + } + // Ends beginning with a hyphen + if (\preg_match("/\-ig(\.|)$/", $datum)) { + if (($spacePos = strrpos($datum, "-")) === false) { + return false; + } + if ($output = self::attempt_splitting(\substr($datum, 0, $spacePos))) { + return new NodaSplitTime('?', $output->end_year, $output->counting_time_month, $output->counting_time_day, + $output->counting_time_indicator, NodaTimeBeforeAfterIndicator::until, '?', $output->end_date); + } + } + if (!empty(\preg_match("/^[0-9]{4}ig$/", $datum))) { + if ($output = self::attempt_splitting(\substr($datum, 0, 4))) { + return new NodaSplitTime('?', $output->end_year, $output->counting_time_month, $output->counting_time_day, + $output->counting_time_indicator, NodaTimeBeforeAfterIndicator::until, '?', $output->end_date); + } + } + if (str_ends_with($datum, '-as évekig') || str_ends_with($datum, '-es évekig')) { + if ($output = self::attempt_splitting(\substr($datum, 0, -2))) { + return new NodaSplitTime('?', $output->end_year, $output->counting_time_month, $output->counting_time_day, + $output->counting_time_indicator, NodaTimeBeforeAfterIndicator::until, '?', $output->end_date); } } // Endings that are extensions of an existing word if (\preg_match("/évektől$/", $datum)) { if ($output = self::attempt_splitting(\substr($datum, 0, -4))) { - $output[1] = "?"; - return $output; + return self::_turn_noda_split_time_to_after($output); } } // Endings beginning with a space (after) if (\preg_match("/ (utantól|utántól)$/", $datum)) { if (($spacePos = strrpos($datum, " ")) === false) { - return []; + return false; } if ($output = self::attempt_splitting(\substr($datum, 0, $spacePos))) { - $output[1] = "?"; - return $output; - } - } - // Endings beginning with a space (until) - if (\preg_match("/ (\(bis)$/", $datum)) { - if (($spacePos = strrpos($datum, " ")) === false) { - return []; - } - if ($output = self::attempt_splitting(\substr($datum, 0, $spacePos))) { - $output[0] = "?"; - return $output; - } - } - // Ends beginning with a hyphen - if (\preg_match("/\-ig(\.|)$/", $datum)) { - if (($spacePos = strrpos($datum, "-")) === false) { - return []; - } - if ($output = self::attempt_splitting(\substr($datum, 0, $spacePos))) { - $output[0] = "?"; - return $output; - } - } - if (!empty(\preg_match("/^[0-9]{4}ig$/", $datum))) { - if ($output = self::attempt_splitting(\substr($datum, 0, 4))) { - $output[0] = "?"; - return $output; - } - } - if (str_ends_with($datum, '-as évekig') || str_ends_with($datum, '-es évekig')) { - if ($output = self::attempt_splitting(\substr($datum, 0, -2))) { - $output[0] = "?"; - return $output; + return new NodaSplitTime($output->start_year, '?', $output->counting_time_month, $output->counting_time_day, + $output->counting_time_indicator, NodaTimeBeforeAfterIndicator::since, $output->start_date, '?'); } } - return []; + return false; } @@ -976,32 +858,31 @@ final class NodaTimeSplitter { * @param string $start Begin time. * @param string $end End time. * - * @return array + * @return NodaSplitTime */ - public static function negotiate_century_span_bce_ce(string $start, string $end):array { + public static function negotiate_century_span_bce_ce(string $start, string $end):NodaSplitTime { $start = \intval($start); $end = \intval($end); if ($start < $end) { - return [(string)($start - 1) . "01", $end . "00", "00", "00", "+", ""]; + return new NodaSplitTime((string)($start - 1) . "01", $end . "00"); } - return [(string)($start) . "00", ($end - 1) . "01", "00", "00", "+", ""]; + return new NodaSplitTime((string)($start) . "00", ($end - 1) . "01"); } /** - * Checks if an input date is a century. + * Checks if an input date is a century. Always returns supposedly positive settings (bc / ce). * * @param string $datum Input date. * - * @return array{0: string, 1: string, 2: string, 3: string, 4: '+'|'-'|'', 5: string}|array{} + * @return NodaSplitTime|false */ - public static function is_century(string $datum):array { + public static function is_century(string $datum):NodaSplitTime|false { $datum = self::clean_input($datum); - $bcBceIndicator = '+'; // TODO: Check if this is duplicate @@ -1010,7 +891,7 @@ final class NodaTimeSplitter { if (\preg_match("/^[0-9]{2}(\.|)" . self::REGEX_CENTURIES ."$/", $datum)) { if ($centuryNo = \intval(\substr($datum, 0, 2))) { $centuryNo--; - return [(string)$centuryNo . "01", \strval($centuryNo + 1) . "00", "00", "00", $bcBceIndicator, ""]; + return new NodaSplitTime((string)$centuryNo . "01", \strval($centuryNo + 1) . "00"); } } @@ -1018,7 +899,7 @@ final class NodaTimeSplitter { if (\preg_match("/^[0-9]\.\ (Jh\.|Jahrhundert|sz|század)$/", $datum)) { if ($centuryNo = \intval(\substr($datum, 0, 1))) { $centuryNo--; - return [(string)$centuryNo . "01", \strval($centuryNo + 1) . "00", "00", "00", $bcBceIndicator, ""]; + return new NodaSplitTime((string)$centuryNo . "01", \strval($centuryNo + 1) . '00'); } } @@ -1051,7 +932,7 @@ final class NodaTimeSplitter { } } - return []; + return false; } @@ -1060,28 +941,65 @@ final class NodaTimeSplitter { * * @param string $datum Input date. * - * @return array{0: string, 1: string, 2: string, 3: string, 4: '+'|'-'|'', 5: string}|array{} + * @return NodaSplitTime|false */ - public static function is_decade(string $datum):array { + public static function is_decade(string $datum):NodaSplitTime|false { $datum = self::clean_input($datum); - $bcBceIndicator = '+'; // 20er Jahre if (\preg_match("/^[0-9]0" . self::REGEX_DECADES . "$/", $datum)) { $start = "19" . \substr($datum, 0, 2); $ende = (string)(\intval($start) + 9); - return [$start, $ende, "00", "00", $bcBceIndicator, ""]; + return new NodaSplitTime($start, $ende); } // 1920er Jahre if (\preg_match("/^[0-9]{3}0" . self::REGEX_DECADES . "$/", $datum)) { $start = \substr($datum, 0, 4); $ende = (string)(\intval($start) + 9); - return [$start, $ende, "00", "00", $bcBceIndicator, ""]; + return new NodaSplitTime($start, $ende); } - return []; + return false; + + } + + /** + * Creates a NodaSplitTime based on an existing one. + * + * @param NodaSplitTime $output Time to translate. + * + * @return NodaSplitTime + */ + private static function _turn_noda_split_time_to_before(NodaSplitTime $output):NodaSplitTime { + + if (empty(trim($output->counting_time_month, "0 .,"))) { + $start_year = strval((int)$output->start_year - 1); + } + else $start_year = $output->start_year; + + return new NodaSplitTime('?', $start_year, $output->counting_time_month, $output->counting_time_day, + $output->counting_time_indicator, NodaTimeBeforeAfterIndicator::before, '?', $output->start_date); + + } + + /** + * Creates a NodaSplitTime based on an existing one. + * + * @param NodaSplitTime $output Time to translate. + * + * @return NodaSplitTime + */ + private static function _turn_noda_split_time_to_after(NodaSplitTime $output):NodaSplitTime { + + if (empty(trim($output->counting_time_month, "0 .,"))) { + $end_year = strval((int)$output->end_year + 1); + } + else $end_year = $output->end_year; + + return new NodaSplitTime($end_year, '?', $output->counting_time_month, $output->counting_time_day, + $output->counting_time_indicator, NodaTimeBeforeAfterIndicator::after, $output->end_date, '?'); } @@ -1090,7 +1008,7 @@ final class NodaTimeSplitter { * * @param string $datum Date. * - * @return array> + * @return array{}|array{0: NodaSplitTime, 1: NodaSplitTime} */ public static function check_is_timespan_from_till(string $datum):array { @@ -1241,11 +1159,11 @@ final class NodaTimeSplitter { } list($start, $end) = $startEnd; - if ($start[4] === '-') return []; + if ($start->counting_time_indicator === NodaCountingTimeIndicator::bce) return []; try { - $startDate = new DateTime($start[4] . $start[0] . '-' . $start[2] . '-' . $start[3]); - $endDate = new DateTime($end[4] . $end[1] . '-' . $end[2] . '-' . $end[3]); + $startDate = $start->startToDateTime(); + $endDate = $end->endToDateTime(); } catch (Exception $e) { return []; @@ -1254,14 +1172,20 @@ final class NodaTimeSplitter { $interval = $startDate->diff($endDate); $days_diff = (int)$interval->format('%a'); + if ($days_diff === 0) { + throw new Exception("Missing interval, failed to calculate (" . $days_diff . ")"); + } + $middle_substraction = round($days_diff / 2); if (!($startDateTimestamp = strtotime($startDate->format('Y-m-d')))) return []; if (!($middleDayTimestamp = strtotime('+' . $middle_substraction . ' days', $startDateTimestamp))) return []; - $middle_day = date('Y-m-d', $middleDayTimestamp); + $middle_year = date('Y', $middleDayTimestamp); + $middle_month = date('m', $middleDayTimestamp); + $middle_day = date('d', $middleDayTimestamp); - $start_name = self::timePartsToTimeName($start); - $end_name = self::timePartsToTimeName($end); + $start_name = $start->toTimeName(); + $end_name = $end->toTimeName(); if (strlen($start_name) === 9 and substr($start_name, 4, 1) === '-') $start_name = substr($start_name, 0, 4); if (strlen($end_name) === 9 and substr($end_name, 4, 1) === '-') $end_name = substr($end_name, 5, 4); @@ -1269,76 +1193,52 @@ final class NodaTimeSplitter { return [ "start_name" => $start_name, "end_name" => $end_name, - "start_year" => $start[0], - "end_year" => $end[1], - "counting_time_year" => substr($middle_day, 0, 4), - "counting_time_month" => substr($middle_day, 5, 2), - "counting_time_day" => substr($middle_day, 8, 2), + "start_year" => $start->start_year, + "end_year" => $end->end_year, + "counting_time_year" => $middle_year, + "counting_time_month" => $middle_month, + "counting_time_day" => $middle_day, "counting_time_bcce" => "+", ]; } - /** - * Cleans invalid outputs from splitting. - * - * @param array{0: string, 1: string, 2: string, 3: string, 4: '+'|'-'|'', 5: string}|array{} $moda Split time to check. - * - * @return array{0: string, 1: string, 2: string, 3: string, 4: '+'|'-'|'', 5: string}|array{} - */ - private static function validate_split_time(array $moda):array { - - if (empty($moda)) return []; - - if ((int)$moda[2] > 12 || (int)$moda[3] > 31) { - return []; - } - - - $month_no_zero = strtr($moda[2], ["0" => "", "1" => "", "2" => "", "3" => "", "4" => "", "5" => "", "6" => "", "7" => "", "8" => "", "9" => ""]); - $day_no_zero = strtr($moda[3], ["0" => "", "1" => "", "2" => "", "3" => "", "4" => "", "5" => "", "6" => "", "7" => "", "8" => "", "9" => ""]); - if (!empty($month_no_zero)) { - throw new Exception("Invalid split month: " . var_export($moda, true)); - } - if (!empty($day_no_zero)) { - throw new Exception("Invalid split day: " . var_export($moda, true)); - } - - return $moda; - - } - /** * Wrapper to check if any splitting command works. * * @param string $datum Input date. * - * @return array{0: string, 1: string, 2: string, 3: string, 4: '+'|'-'|'', 5: string}|array{} + * @return NodaSplitTime|false */ - public static function attempt_splitting(string $datum):array { + public static function attempt_splitting(string $datum):NodaSplitTime|false { - if (!empty($moda = self::is_timespan($datum))) { - return self::validate_split_time($moda); + try { + if (!empty($moda = self::is_timespan($datum))) { + return $moda; + } + + if (!empty($moda = self::is_incomplete_date($datum))) { + return $moda; + } + + if (!empty($moda = self::is_valid_date($datum))) { + return $moda; + } + + if (!empty($moda = self::is_valid_date_hungarian($datum))) { + return $moda; + } + + if (!empty($moda = self::is_century($datum))) { + return $moda; + } + + if (!empty($moda = self::is_decade($datum))) { + return $moda; + } } - - if (!empty($moda = self::is_incomplete_date($datum))) { - return self::validate_split_time($moda); - } - - if (!empty($moda = self::is_valid_date($datum))) { - return self::validate_split_time($moda); - } - - if (!empty($moda = self::is_valid_date_hungarian($datum))) { - return self::validate_split_time($moda); - } - - if (!empty($moda = self::is_century($datum))) { - return self::validate_split_time($moda); - } - - if (!empty($moda = self::is_decade($datum))) { - return self::validate_split_time($moda); + catch (MDgenericInvalidInputsException $e) { + return false; } // 2015. 05. @@ -1349,7 +1249,7 @@ final class NodaTimeSplitter { } } - return []; + return false; } } diff --git a/tests/NodaTimeSplitterTest.php b/tests/NodaTimeSplitterTest.php index 8853222..e49e277 100644 --- a/tests/NodaTimeSplitterTest.php +++ b/tests/NodaTimeSplitterTest.php @@ -24,8 +24,23 @@ final class NodaTimeSplitterTest extends TestCase { */ public function testSplitSimpleDatesGerman():void { + $output = NodaTimeSplitter::attempt_splitting("2. Januar 2020"); + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ + 0 => "2020", + 1 => "2020", + 2 => "01", + 3 => "02", + 4 => "+", + 5 => "", + ]); + self::assertEquals($output->toTimeName(), "02.01.2020"); + self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020); + + $output = NodaTimeSplitter::attempt_splitting("02.1.25 v. Chr"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "-25", 1 => "-25", 2 => "01", @@ -33,11 +48,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "-", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "02.01.25 v. Chr."); + self::assertEquals($output->toTimeName(), "02.01.25 v. Chr."); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 25); $output = NodaTimeSplitter::attempt_splitting("2.01.25 v. Chr"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "-25", 1 => "-25", 2 => "01", @@ -45,11 +61,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "-", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "02.01.25 v. Chr."); + self::assertEquals($output->toTimeName(), "02.01.25 v. Chr."); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 25); $output = NodaTimeSplitter::attempt_splitting("02.01.25 v. Chr"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "-25", 1 => "-25", 2 => "01", @@ -57,11 +74,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "-", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "02.01.25 v. Chr."); + self::assertEquals($output->toTimeName(), "02.01.25 v. Chr."); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 25); $output = NodaTimeSplitter::attempt_splitting("2.1.25 v. Chr"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "-25", 1 => "-25", 2 => "01", @@ -69,11 +87,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "-", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "02.01.25 v. Chr."); + self::assertEquals($output->toTimeName(), "02.01.25 v. Chr."); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 25); $output = NodaTimeSplitter::attempt_splitting("2.1.2020"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "2020", 1 => "2020", 2 => "01", @@ -81,11 +100,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "02.01.2020"); + self::assertEquals($output->toTimeName(), "02.01.2020"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020); $output = NodaTimeSplitter::attempt_splitting("02.01.2020"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "2020", 1 => "2020", 2 => "01", @@ -93,23 +113,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "02.01.2020"); - self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020); - - $output = NodaTimeSplitter::attempt_splitting("2. Januar 2020"); - self::assertEquals($output, [ - 0 => "2020", - 1 => "2020", - 2 => "01", - 3 => "02", - 4 => "+", - 5 => "", - ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "02.01.2020"); + self::assertEquals($output->toTimeName(), "02.01.2020"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020); $output = NodaTimeSplitter::attempt_splitting("1920-1929"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "1920", 1 => "1929", 2 => "00", @@ -117,11 +126,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1920-1929"); + self::assertEquals($output->toTimeName(), "1920-1929"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925); $output = NodaTimeSplitter::attempt_splitting("20er"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "1920", 1 => "1929", 2 => "00", @@ -129,11 +139,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1920-1929"); + self::assertEquals($output->toTimeName(), "1920-1929"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925); $output = NodaTimeSplitter::attempt_splitting("1920-1929"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "1920", 1 => "1929", 2 => "00", @@ -141,11 +152,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1920-1929"); + self::assertEquals($output->toTimeName(), "1920-1929"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925); $output = NodaTimeSplitter::attempt_splitting("1920er Jahre"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "1920", 1 => "1929", 2 => "00", @@ -153,11 +165,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1920-1929"); + self::assertEquals($output->toTimeName(), "1920-1929"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925); $output = NodaTimeSplitter::attempt_splitting("Vor Dezember 2020"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "?", 1 => "2020", 2 => "12", @@ -165,11 +178,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "Vor", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Vor Dezember 2020"); + self::assertEquals($output->toTimeName(), "Vor Dezember 2020"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020); $output = NodaTimeSplitter::attempt_splitting("Vor 2020"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "?", 1 => "2019", 2 => "00", @@ -177,11 +191,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "Vor", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Vor 2020"); + self::assertEquals($output->toTimeName(), "Vor 2020"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020); $output = NodaTimeSplitter::attempt_splitting("Nach Januar 2020"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "2020", 1 => "?", 2 => "01", @@ -189,11 +204,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "Nach", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Nach Januar 2020"); + self::assertEquals($output->toTimeName(), "Nach Januar 2020"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020); $output = NodaTimeSplitter::attempt_splitting("Januar 2020"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "2020", 1 => "2020", 2 => "01", @@ -201,11 +217,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Januar 2020"); + self::assertEquals($output->toTimeName(), "Januar 2020"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020); $output = NodaTimeSplitter::attempt_splitting("Januar 1217"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "1217", 1 => "1217", 2 => "01", @@ -214,11 +231,12 @@ final class NodaTimeSplitterTest extends TestCase { 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Januar 1217"); + self::assertEquals($output->toTimeName(), "Januar 1217"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1217); $output = NodaTimeSplitter::attempt_splitting("Januar 1520"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "1520", 1 => "1520", 2 => "01", @@ -227,11 +245,12 @@ final class NodaTimeSplitterTest extends TestCase { 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Januar 1520"); + self::assertEquals($output->toTimeName(), "Januar 1520"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1520); $output = NodaTimeSplitter::attempt_splitting("Januar 1001"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "1001", 1 => "1001", 2 => "01", @@ -240,11 +259,12 @@ final class NodaTimeSplitterTest extends TestCase { 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Januar 1001"); + self::assertEquals($output->toTimeName(), "Januar 1001"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1001); $output = NodaTimeSplitter::attempt_splitting("Januar 2780"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "2780", 1 => "2780", 2 => "01", @@ -253,11 +273,12 @@ final class NodaTimeSplitterTest extends TestCase { 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Januar 2780"); + self::assertEquals($output->toTimeName(), "Januar 2780"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2780); $output = NodaTimeSplitter::attempt_splitting("Nach 60er Jahre"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "1970", 1 => "?", 2 => "00", @@ -265,11 +286,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "Nach", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Nach 1969"); + self::assertEquals($output->toTimeName(), "Nach 1969"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1969); $output = NodaTimeSplitter::attempt_splitting("Nach 2020"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "2021", 1 => "?", 2 => "00", @@ -277,23 +299,25 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "Nach", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Nach 2020"); + self::assertEquals($output->toTimeName(), "Nach 2020"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020); $output = NodaTimeSplitter::attempt_splitting("Bis Januar 2020"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "?", 1 => "2020", 2 => "01", 3 => "00", 4 => "+", - 5 => "", + 5 => "Bis", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Bis Januar 2020"); + self::assertEquals($output->toTimeName(), "Bis Januar 2020"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020); $output = NodaTimeSplitter::attempt_splitting("Januar 2020"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "2020", 1 => "2020", 2 => "01", @@ -301,12 +325,13 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Januar 2020"); + self::assertEquals($output->toTimeName(), "Januar 2020"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020); // Intl' month: 2020-01 $output = NodaTimeSplitter::attempt_splitting("2020-01"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "2020", 1 => "2020", 2 => "01", @@ -314,11 +339,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Januar 2020"); + self::assertEquals($output->toTimeName(), "Januar 2020"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020); $output = NodaTimeSplitter::attempt_splitting("Januar 2020 v. Chr."); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "-2020", 1 => "-2020", 2 => "01", @@ -326,12 +352,13 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "-", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Januar 2020 v. Chr."); + self::assertEquals($output->toTimeName(), "Januar 2020 v. Chr."); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020); // 5-Digit timespans BCE $output = NodaTimeSplitter::attempt_splitting("40000-25000 vor Christus"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "-40000", 1 => "-25000", 2 => "00", @@ -339,12 +366,13 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "-", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "40000-25000 v. Chr."); + self::assertEquals($output->toTimeName(), "40000-25000 v. Chr."); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 32500); // 5-Digit timespans BCE $output = NodaTimeSplitter::attempt_splitting("40000-25000 v.C."); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "-40000", 1 => "-25000", 2 => "00", @@ -352,11 +380,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "-", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "40000-25000 v. Chr."); + self::assertEquals($output->toTimeName(), "40000-25000 v. Chr."); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 32500); $output = NodaTimeSplitter::attempt_splitting("20. Jahrhundert v. Chr."); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "-2000", 1 => "-1901", 2 => "00", @@ -364,11 +393,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "-", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "2000-1901 v. Chr."); + self::assertEquals($output->toTimeName(), "2000-1901 v. Chr."); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1950); $output = NodaTimeSplitter::attempt_splitting("20. Jh."); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "1901", 1 => "2000", 2 => "00", @@ -376,11 +406,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1901-2000"); + self::assertEquals($output->toTimeName(), "1901-2000"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1951); $output = NodaTimeSplitter::attempt_splitting("20. Jhd."); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "1901", 1 => "2000", 2 => "00", @@ -388,11 +419,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1901-2000"); + self::assertEquals($output->toTimeName(), "1901-2000"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1951); $output = NodaTimeSplitter::attempt_splitting("20. Jhdt."); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "1901", 1 => "2000", 2 => "00", @@ -400,11 +432,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1901-2000"); + self::assertEquals($output->toTimeName(), "1901-2000"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1951); $output = NodaTimeSplitter::attempt_splitting("20. Jahrhundert"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "1901", 1 => "2000", 2 => "00", @@ -412,11 +445,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1901-2000"); + self::assertEquals($output->toTimeName(), "1901-2000"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1951); $output = NodaTimeSplitter::attempt_splitting("20.-19. Jahrhundert v. Chr."); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "-2000", 1 => "-1801", 2 => "00", @@ -424,23 +458,25 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "-", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "2000-1801 v. Chr."); + self::assertEquals($output->toTimeName(), "2000-1801 v. Chr."); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1900); $output = NodaTimeSplitter::attempt_splitting("Bis 20.-19. Jahrhundert v. Chr."); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "?", 1 => "-1801", 2 => "00", 3 => "00", 4 => "-", - 5 => "", + 5 => "Bis", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Bis 1801 v. Chr."); + self::assertEquals($output->toTimeName(), "Bis 1801 v. Chr."); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1801); $output = NodaTimeSplitter::attempt_splitting("6 November 1978"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "1978", 1 => "1978", 2 => "11", @@ -448,7 +484,7 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "06.11.1978"); + self::assertEquals($output->toTimeName(), "06.11.1978"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1978); } @@ -465,7 +501,8 @@ final class NodaTimeSplitterTest extends TestCase { public function testSplitSimpleDatesEnglish():void { $output = NodaTimeSplitter::attempt_splitting("1925 BCE"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "-1925", 1 => "-1925", 2 => "00", @@ -473,11 +510,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "-", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1925 v. Chr."); + self::assertEquals($output->toTimeName(), "1925 v. Chr."); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925); $output = NodaTimeSplitter::attempt_splitting("1925 CE"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "1925", 1 => "1925", 2 => "00", @@ -485,7 +523,7 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1925"); + self::assertEquals($output->toTimeName(), "1925"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925); } @@ -502,7 +540,8 @@ final class NodaTimeSplitterTest extends TestCase { public function testSplitSimpleDatesHungarian():void { $output = NodaTimeSplitter::attempt_splitting("2020.01.02."); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "2020", 1 => "2020", 2 => "01", @@ -510,11 +549,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "02.01.2020"); + self::assertEquals($output->toTimeName(), "02.01.2020"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020); $output = NodaTimeSplitter::attempt_splitting("2020. januar. 2."); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "2020", 1 => "2020", 2 => "01", @@ -522,11 +562,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "02.01.2020"); + self::assertEquals($output->toTimeName(), "02.01.2020"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020); $output = NodaTimeSplitter::attempt_splitting("2020.01.2."); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "2020", 1 => "2020", 2 => "01", @@ -534,11 +575,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "02.01.2020"); + self::assertEquals($output->toTimeName(), "02.01.2020"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020); $output = NodaTimeSplitter::attempt_splitting("2020.1.2."); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "2020", 1 => "2020", 2 => "01", @@ -546,11 +588,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "02.01.2020"); + self::assertEquals($output->toTimeName(), "02.01.2020"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020); $output = NodaTimeSplitter::attempt_splitting("2020. Januar 2."); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "2020", 1 => "2020", 2 => "01", @@ -558,11 +601,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "02.01.2020"); + self::assertEquals($output->toTimeName(), "02.01.2020"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020); $output = NodaTimeSplitter::attempt_splitting("2020-01-02"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "2020", 1 => "2020", 2 => "01", @@ -570,11 +614,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "02.01.2020"); + self::assertEquals($output->toTimeName(), "02.01.2020"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020); $output = NodaTimeSplitter::attempt_splitting("1920-tól 1929-ig"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "1920", 1 => "1929", 2 => "00", @@ -582,11 +627,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1920-1929"); + self::assertEquals($output->toTimeName(), "1920-1929"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925); $output = NodaTimeSplitter::attempt_splitting("1920-1929 között"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "1920", 1 => "1929", 2 => "00", @@ -594,11 +640,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1920-1929"); + self::assertEquals($output->toTimeName(), "1920-1929"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925); $output = NodaTimeSplitter::attempt_splitting("1920-től 1929-ig"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "1920", 1 => "1929", 2 => "00", @@ -606,24 +653,26 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1920-1929"); + self::assertEquals($output->toTimeName(), "1920-1929"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925); // From 1920 onwards $output = NodaTimeSplitter::attempt_splitting("1920 utántól"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "1920", 1 => "?", 2 => "00", 3 => "00", 4 => "+", - 5 => "", + 5 => "Seit", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Seit 1920"); + self::assertEquals($output->toTimeName(), "Seit 1920"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1920); $output = NodaTimeSplitter::attempt_splitting("1920-es évek"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "1920", 1 => "1929", 2 => "00", @@ -631,22 +680,24 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1920-1929"); + self::assertEquals($output->toTimeName(), "1920-1929"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925); $output = NodaTimeSplitter::attempt_splitting("1920-es évekig"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "?", 1 => "1929", 2 => "00", 3 => "00", 4 => "+", - 5 => "", + 5 => "Bis", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Bis 1929"); + self::assertEquals($output->toTimeName(), "Bis 1929"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1929); $output = NodaTimeSplitter::attempt_splitting("2020. Januar"); + self::assertNotEmpty($output); self::assertEquals([ 0 => "2020", 1 => "2020", @@ -654,12 +705,13 @@ final class NodaTimeSplitterTest extends TestCase { 3 => "00", 4 => "+", 5 => "", - ], $output); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Januar 2020"); + ], $output->toOldFormat()); + self::assertEquals($output->toTimeName(), "Januar 2020"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020); $output = NodaTimeSplitter::attempt_splitting("Kr. e. 2020. Januar"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "-2020", 1 => "-2020", 2 => "01", @@ -667,11 +719,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "-", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Januar 2020 v. Chr."); + self::assertEquals($output->toTimeName(), "Januar 2020 v. Chr."); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020); $output = NodaTimeSplitter::attempt_splitting("20. sz"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "1901", 1 => "2000", 2 => "00", @@ -679,11 +732,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1901-2000"); + self::assertEquals($output->toTimeName(), "1901-2000"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1951); $output = NodaTimeSplitter::attempt_splitting("III. század"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "201", 1 => "300", 2 => "00", @@ -691,11 +745,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "201-300 n. Chr."); + self::assertEquals($output->toTimeName(), "201-300 n. Chr."); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 251); $output = NodaTimeSplitter::attempt_splitting("20th century"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "1901", 1 => "2000", 2 => "00", @@ -703,11 +758,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1901-2000"); + self::assertEquals($output->toTimeName(), "1901-2000"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1951); $output = NodaTimeSplitter::attempt_splitting("20. század"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "1901", 1 => "2000", 2 => "00", @@ -715,11 +771,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1901-2000"); + self::assertEquals($output->toTimeName(), "1901-2000"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1951); $output = NodaTimeSplitter::attempt_splitting("20.század"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "1901", 1 => "2000", 2 => "00", @@ -727,11 +784,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1901-2000"); + self::assertEquals($output->toTimeName(), "1901-2000"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1951); $output = NodaTimeSplitter::attempt_splitting("Kr. e. 20. század"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "-2000", 1 => "-1901", 2 => "00", @@ -739,11 +797,12 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "-", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "2000-1901 v. Chr."); + self::assertEquals($output->toTimeName(), "2000-1901 v. Chr."); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1950); $output = NodaTimeSplitter::attempt_splitting("Kr. e. 20.-19. század"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "-2000", 1 => "-1801", 2 => "00", @@ -751,25 +810,27 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "-", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "2000-1801 v. Chr."); + self::assertEquals($output->toTimeName(), "2000-1801 v. Chr."); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1900); $output = NodaTimeSplitter::attempt_splitting("Kr. e. 20.-19. század-ig"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "?", 1 => "-1801", 2 => "00", 3 => "00", 4 => "-", - 5 => "", + 5 => "Bis", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Bis 1801 v. Chr."); + self::assertEquals($output->toTimeName(), "Bis 1801 v. Chr."); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1801); /* * TODO $output = NodaTimeSplitter::attempt_splitting("1900 előtt"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "?", 1 => "1899", 2 => "00", @@ -777,36 +838,39 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Vor 1900"); + self::assertEquals($output->toTimeName(), "Vor 1900"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1899); */ $output = NodaTimeSplitter::attempt_splitting("1900-ig"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "?", 1 => "1900", 2 => "00", 3 => "00", 4 => "+", - 5 => "", + 5 => "Bis", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Bis 1900"); + self::assertEquals($output->toTimeName(), "Bis 1900"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1900); $output = NodaTimeSplitter::attempt_splitting("1900ig"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "?", 1 => "1900", 2 => "00", 3 => "00", 4 => "+", - 5 => "", + 5 => "Bis", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Bis 1900"); + self::assertEquals($output->toTimeName(), "Bis 1900"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1900); $output = NodaTimeSplitter::attempt_splitting("2020. december előtt"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "?", 1 => "2020", 2 => "12", @@ -814,7 +878,7 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "Vor", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Vor Dezember 2020"); + self::assertEquals($output->toTimeName(), "Vor Dezember 2020"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020); } @@ -831,7 +895,8 @@ final class NodaTimeSplitterTest extends TestCase { public function testSplitSimpleDatesUkrainian():void { $output = NodaTimeSplitter::attempt_splitting("2020 p"); - self::assertEquals($output, [ + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ 0 => "2020", 1 => "2020", 2 => "00", @@ -839,7 +904,7 @@ final class NodaTimeSplitterTest extends TestCase { 4 => "+", 5 => "", ]); - self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "2020"); + self::assertEquals($output->toTimeName(), "2020"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020); } @@ -864,8 +929,8 @@ final class NodaTimeSplitterTest extends TestCase { "start_year" => '2004', "end_year" => '2004', "counting_time_year" => "2004", - "counting_time_month" => "01", - "counting_time_day" => "16", + "counting_time_month" => "02", + "counting_time_day" => "01", "counting_time_bcce" => "+", ]); @@ -878,8 +943,8 @@ final class NodaTimeSplitterTest extends TestCase { "start_year" => '2004', "end_year" => '2004', "counting_time_year" => "2004", - "counting_time_month" => "01", - "counting_time_day" => "16", + "counting_time_month" => "02", + "counting_time_day" => "01", "counting_time_bcce" => "+", ]); @@ -925,8 +990,8 @@ final class NodaTimeSplitterTest extends TestCase { 'end_name' => "1900", "start_year" => '1601', "end_year" => '1900', - "counting_time_year" => "1750", - "counting_time_month" => "06", + "counting_time_year" => "1751", + "counting_time_month" => "01", "counting_time_day" => "01", "counting_time_bcce" => "+", ]); @@ -939,8 +1004,8 @@ final class NodaTimeSplitterTest extends TestCase { 'end_name' => "1969", "start_year" => '1950', "end_year" => '1969', - "counting_time_year" => "1959", - "counting_time_month" => "06", + "counting_time_year" => "1960", + "counting_time_month" => "01", "counting_time_day" => "01", "counting_time_bcce" => "+", ]);
' . $tlLoader->tl("tempi", "tempi", "time_tool") . 'toTimeName()) !== "") { $output .= "&zeit_name_neu={$newTimeName}"; } - $output .= '&zeit_beginn_neu=' . $moda[0] . '&zeit_ende_neu=' . $moda[1] . '&zeit_zaehlzeit_vorzeichen_neu=' . urlencode($moda[4]) . '&zeit_zaehlzeit_jahr_neu=' . $zaehlzeit_jahr . '&zeit_zaehlzeit_monat_neu=' . $moda[2] . '&zeit_zaehlzeit_tag_neu=' . $moda[3] . '&zeit_status_neu=%2B" class="icons iconsBell buttonLike" id="splitTimeLink">+'; + $output .= '&zeit_beginn_neu=' . $moda->start_year . '&zeit_ende_neu=' . $moda->end_year . '&zeit_zaehlzeit_vorzeichen_neu=' . urlencode($moda->counting_time_indicator->toString()) . '&zeit_zaehlzeit_jahr_neu=' . $zaehlzeit_jahr . '&zeit_zaehlzeit_monat_neu=' . $moda->counting_time_month . '&zeit_zaehlzeit_tag_neu=' . $moda->counting_time_day . '&zeit_status_neu=%2B" class="icons iconsBell buttonLike" id="splitTimeLink">+'; if (!empty($newTimeName)) { $output .= $newTimeName; } else { - if (!empty(trim($moda[3], " 0")) and !empty(trim($moda[2], " 0"))) $output .= $moda[3] . '.' . $moda[2] . '.' . $moda[0]; - else if ($moda[0] !== $moda[1]) $output .= $moda[0] . "-" . $moda[1]; - else if (!empty(trim($moda[2], " 0"))) $output .= "{$moda[2]}.{$moda[0]}"; - else $output .= $moda[0]; + if (!empty(trim($moda->counting_time_day, " 0")) and !empty(trim($moda->counting_time_month, " 0"))) $output .= $moda->counting_time_day . '.' . $moda->counting_time_month . '.' . $moda->start_year; + else if ($moda->start_year !== $moda->end_year) $output .= $moda->start_year . "-" . $moda->end_year; + else if (!empty(trim($moda->counting_time_month, " 0"))) $output .= "{$moda->counting_time_month}.{$moda->start_year}"; + else $output .= $moda->start_year; } $output .= ' - ' . $tlLoader->tl("tempi", "tempi", "time_disassemble") . '