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. |      * Contains special rules for incorrectly or incompletely spelled out timespan names. | ||||||
|      * To be called by self::attempt_splitting_from_till(). |      * 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; |         return false; | ||||||
|  |  | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -211,6 +211,13 @@ final class NodaTimeSplitterTest extends TestCase { | |||||||
|                     end_date: '-0001-12-31'), |                     end_date: '-0001-12-31'), | ||||||
|                 "28-1 v. Chr.", |                 "28-1 v. Chr.", | ||||||
|             ], |             ], | ||||||
|  |             "1. Hälfte des 19. Jahrhunderts" => [ | ||||||
|  |                 "1. Hälfte des 19. Jahrhunderts", | ||||||
|  |                 new NodaSplitTime('1800', '1850', | ||||||
|  |                     start_date: '1800-01-01', | ||||||
|  |                     end_date: '1850-12-31'), | ||||||
|  |                 "1800-1850", | ||||||
|  |             ], | ||||||
|         ]; |         ]; | ||||||
|  |  | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user