Extend NodaTimeSplitter
This commit is contained in:
		| @@ -58,6 +58,8 @@ final class NodaTimeSplitter { | ||||
|  | ||||
|     const STRINGS_TO_CLEAN = [ | ||||
|         "között" => "", | ||||
|         " рр." => "", | ||||
|         " рр" => "", | ||||
|         "nach Christus" => "", | ||||
|         "n. Christus" => "", | ||||
|         "nach Chr." => "", | ||||
| @@ -69,6 +71,7 @@ final class NodaTimeSplitter { | ||||
|         "BCE" => "v. Chr.", | ||||
|         "CE" => "", | ||||
|         "vor Christus" => "v. Chr.", | ||||
|         " до н. е." => "v. Chr.", | ||||
|     ]; | ||||
|  | ||||
|     const STRINGS_TO_CLEAN_START = [ | ||||
| @@ -133,6 +136,7 @@ final class NodaTimeSplitter { | ||||
|     ]; | ||||
|  | ||||
|     private const REGEX_CENTURIES = '(\ |)(Jh\.|Jhd(|\.)|Jhdt(|\.)|Jahrhundert|sz|század|th century|ст|ст\.)'; | ||||
|     private const REGEX_DECADES = '(s|er|er\ Jahre|(\-|\ )es\ évek|(\-|\ )as\ \évek|\ évek|\-es\ években|\-ті)'; | ||||
|  | ||||
|     /** | ||||
|      * Cleans input strings by trimming obsolete stuff. | ||||
| @@ -555,10 +559,6 @@ final class NodaTimeSplitter { | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         if ($datum === '1978. július 7 elött') { | ||||
|             throw new Exception(var_export($monat, true)); | ||||
|         } | ||||
|  | ||||
|         if (!empty($monat) && empty($day) && preg_match('~[0-9]+~', substr($datum, -3))) { | ||||
|             return []; | ||||
|         } | ||||
| @@ -864,14 +864,17 @@ final class NodaTimeSplitter { | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         if (\preg_match("/\ (\(vor|\(Vor|vor)$/", $datum)) { | ||||
|             if (($spacePos = \strpos($datum, " ")) === false) { | ||||
|         if (\preg_match("/\ (\(vor|\(Vor|vor|előtt)$/", $datum)) { | ||||
|             if (($spacePos = \strrpos($datum, " ")) === false) { | ||||
|                 return []; | ||||
|             } | ||||
|             if ($output = self::attempt_splitting(\substr($datum, 0, $spacePos))) { | ||||
|  | ||||
|                 $output[0] = "?"; | ||||
|                 if (empty(trim($output[2], "0 .,"))) $output[1] = \strval(\intval($output[1]) - 1); | ||||
|                 // 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; | ||||
|             } | ||||
| @@ -951,6 +954,12 @@ final class NodaTimeSplitter { | ||||
|                 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 []; | ||||
|  | ||||
| @@ -1054,14 +1063,14 @@ final class NodaTimeSplitter { | ||||
|         $bcBceIndicator = '+'; | ||||
|  | ||||
|         // 20er Jahre | ||||
|         if (\preg_match("/^[0-9]0(er|er\ Jahre|\-es\ évek|\-as\ \évek)$/", $datum)) { | ||||
|         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, ""]; | ||||
|         } | ||||
|  | ||||
|         // 1920er Jahre | ||||
|         if (\preg_match("/^[0-9]{3}0(s|er|er\ Jahre|(\-|\ )es\ évek|(\-|\ )as\ \évek)$/", $datum)) { | ||||
|         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, ""]; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user