Allow splitting of German short decade names: 20er or 1920er

This commit is contained in:
Joshua Ramon Enslin 2020-09-27 17:12:34 +02:00 committed by Stefan Rohde-Enslin
parent 91f435a2e4
commit 67cc76cff9
2 changed files with 14 additions and 2 deletions

View File

@ -797,13 +797,13 @@ final class NodaTimeSplitter {
$datum = self::clean_input($datum);
$bcBceIndicator = '+';
if (preg_match("/^[0-9]0(er\ Jahre|\-es\ évek|\-as\ \évek)$/", $datum)) {
if (preg_match("/^[0-9]0(er|er\ Jahre|\-es\ évek|\-as\ \évek)$/", $datum)) {
$start = "19" . substr($datum, 0, 2);
$ende = (string)(intval($start) + 9);
return [$start, $ende, "00", "00", $bcBceIndicator, ""];
}
if (preg_match("/^[0-9][0-9][0-9]0(er\ Jahre|\-es\ évek|\-as\ \évek)$/", $datum)) {
if (preg_match("/^[0-9][0-9][0-9]0(er|er\ Jahre|\-es\ évek|\-as\ \évek)$/", $datum)) {
$start = substr($datum, 0, 4);
$ende = (string)(intval($start) + 9);
return [$start, $ende, "00", "00", $bcBceIndicator, ""];

View File

@ -120,6 +120,18 @@ final class NodaTimeSplitterTest extends TestCase {
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1920-1929");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925);
$output = NodaTimeSplitter::attempt_splitting("20er");
self::assertEquals($output, [
0 => "1920",
1 => "1929",
2 => "00",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1920-1929");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925);
$output = NodaTimeSplitter::attempt_splitting("1920er Jahre");
self::assertEquals($output, [
0 => "1920",