Support splitting times like "1. Hälfte des 19. Jahrhunderts"
This commit is contained in:
		| @@ -1125,6 +1125,33 @@ final class NodaTimeSplitter { | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Rewrites special formulations of a date. | ||||
|      * | ||||
|      * @param string $datum Date. | ||||
|      * | ||||
|      * @return string|false | ||||
|      */ | ||||
|     private static function _rewrite_special_cases_regular(string $datum):string|false { | ||||
|  | ||||
|         if (\preg_match("/^(1|2)\.\ Hälfte(|\ des)\ [0-9]{2}\.\ Jahrhundert(|s)$/", $datum)) { | ||||
|  | ||||
|             $half = substr($datum, 0, 1); | ||||
|             $number = substr(ltrim(substr($datum, 10), "des Hälfte"), 0, 2); | ||||
|             if (is_numeric($number)) { | ||||
|                 $num = (int)$number; | ||||
|                 $targetCentury = $num - 1; | ||||
|                 return match((int)$half) { | ||||
|                     1 => $targetCentury . "00-" . $targetCentury . "50", | ||||
|                     2 => $targetCentury . "50-" . $targetCentury . "99", | ||||
|                 }; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return false; | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Contains special rules for incorrectly or incompletely spelled out timespan names. | ||||
|      * To be called by self::attempt_splitting_from_till(). | ||||
| @@ -1401,6 +1428,10 @@ final class NodaTimeSplitter { | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         if ($rewrite = self::_rewrite_special_cases_regular($datum)) { | ||||
|             return self::attempt_splitting($rewrite); | ||||
|         } | ||||
|  | ||||
|         return false; | ||||
|  | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user