Allow splitting times "Nach 1905" ("Nach " followed by 4 digit time

number)
This commit is contained in:
Joshua Ramon Enslin 2020-10-04 17:39:34 +02:00 committed by Stefan Rohde-Enslin
parent 36d27e0f73
commit 2a57537436
2 changed files with 46 additions and 2 deletions

View File

@ -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 [];

View File

@ -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, []);
}