diff --git a/src/NodaTimeSplitter.php b/src/NodaTimeSplitter.php index dec8721..f3b0ef8 100644 --- a/src/NodaTimeSplitter.php +++ b/src/NodaTimeSplitter.php @@ -189,7 +189,12 @@ final class NodaTimeSplitter { */ public static function timePartsToTimeName(array $moda):string { - if ($moda[0] === "?") { + if (!empty($moda[5]) and $moda[5] === "Nach" and $moda[1] === "?") { + $moda[0] = strval(intval($moda[0]) - 1); + $moda[1] = $moda[0]; + $prefix = "Nach "; + } + else if ($moda[0] === "?") { $prefix = "Bis "; $moda[0] = $moda[1]; } @@ -245,6 +250,9 @@ final class NodaTimeSplitter { } if ($moda[1] === "?") { + if (!empty($moda[5]) and $moda[5] === "Nach") { + return abs(intval($moda[0])) - 1; + } return abs(intval($moda[0])); } @@ -673,6 +681,18 @@ final class NodaTimeSplitter { return ["?", $start, "00", "00", "+", ""]; } + if (preg_match("/^(Nach|nach)\ [0-9]{4}/", $datum)) { + if (($spacePos = strpos($datum, " ")) === false) { + return []; + } + if ($output = self::attempt_splitting(substr($datum, $spacePos))) { + $output[1] = "?"; + $output[0] = strval((intval($output[0]) + 1)); + $output[5] = "Nach"; + return $output; + } + } + if (preg_match("/^(Ab|Seit|seit)\ /", $datum)) { if (($spacePos = strpos($datum, " ")) === false) { return []; diff --git a/tests/NodaTimeSplitterTest.php b/tests/NodaTimeSplitterTest.php index c287c87..41317f8 100644 --- a/tests/NodaTimeSplitterTest.php +++ b/tests/NodaTimeSplitterTest.php @@ -144,6 +144,30 @@ final class NodaTimeSplitterTest extends TestCase { self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1920-1929"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925); + $output = NodaTimeSplitter::attempt_splitting("Nach 2020"); + self::assertEquals($output, [ + 0 => "2021", + 1 => "?", + 2 => "00", + 3 => "00", + 4 => "+", + 5 => "Nach", + ]); + self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Nach 2020"); + self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020); + + $output = NodaTimeSplitter::attempt_splitting("Bis Januar 2020"); + self::assertEquals($output, [ + 0 => "?", + 1 => "2020", + 2 => "01", + 3 => "00", + 4 => "+", + 5 => "", + ]); + self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Bis Januar 2020"); + self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020); + $output = NodaTimeSplitter::attempt_splitting("Januar 2020"); self::assertEquals($output, [ 0 => "2020", @@ -449,7 +473,7 @@ final class NodaTimeSplitterTest extends TestCase { $output = NodaTimeSplitter::attempt_splitting("Januar-Februar"); self::assertEquals($output, []); - $output = NodaTimeSplitter::attempt_splitting("Nach 1944"); + $output = NodaTimeSplitter::attempt_splitting("Nach Januar 1944"); self::assertEquals($output, []); }