Allow splitting times "before <X>"
This commit is contained in:
parent
a0037c9883
commit
1685d78f65
|
@ -189,7 +189,12 @@ final class NodaTimeSplitter {
|
|||
*/
|
||||
public static function timePartsToTimeName(array $moda):string {
|
||||
|
||||
if (!empty($moda[5]) and $moda[5] === "Nach" and $moda[1] === "?") {
|
||||
if (!empty($moda[5]) and $moda[5] === "Vor" and $moda[0] === "?") {
|
||||
if (empty(trim($moda[2], "0 "))) $moda[1] = strval(intval($moda[1]) + 1);
|
||||
$moda[0] = $moda[1];
|
||||
$prefix = "Vor ";
|
||||
}
|
||||
else if (!empty($moda[5]) and $moda[5] === "Nach" and $moda[1] === "?") {
|
||||
if (empty(trim($moda[2], "0 "))) $moda[0] = strval(intval($moda[0]) - 1);
|
||||
$moda[1] = $moda[0];
|
||||
$prefix = "Nach ";
|
||||
|
@ -246,6 +251,9 @@ final class NodaTimeSplitter {
|
|||
public static function timePartsToCountingYear(array $moda):int {
|
||||
|
||||
if ($moda[0] === "?") {
|
||||
if (!empty($moda[5]) and $moda[5] === "Vor" and empty(trim($moda[2], " 0"))) {
|
||||
return abs(intval($moda[1])) + 1;
|
||||
}
|
||||
return abs(intval($moda[1]));
|
||||
}
|
||||
|
||||
|
@ -698,6 +706,7 @@ final class NodaTimeSplitter {
|
|||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
if (preg_match("/^[0-9]{4}\ (\(nach)/", $datum)) {
|
||||
if (($spacePos = strpos($datum, " ")) === false) {
|
||||
return [];
|
||||
|
@ -716,6 +725,19 @@ final class NodaTimeSplitter {
|
|||
}
|
||||
}
|
||||
|
||||
if (preg_match("/^(Vor|vor)\ /", $datum)) {
|
||||
if (($spacePos = strpos($datum, " ")) === false) {
|
||||
return [];
|
||||
}
|
||||
if ($output = self::attempt_splitting(substr($datum, $spacePos))) {
|
||||
|
||||
$output[0] = "?";
|
||||
if (empty(trim($output[2], "0 .,"))) $output[1] = strval((intval($output[1]) - 1));
|
||||
$output[5] = "Vor";
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
if (preg_match("/^(Ab|Seit|seit)\ /", $datum)) {
|
||||
if (($spacePos = strpos($datum, " ")) === false) {
|
||||
return [];
|
||||
|
|
|
@ -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("Vor Dezember 2020");
|
||||
self::assertEquals($output, [
|
||||
0 => "?",
|
||||
1 => "2020",
|
||||
2 => "12",
|
||||
3 => "00",
|
||||
4 => "+",
|
||||
5 => "Vor",
|
||||
]);
|
||||
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Vor Dezember 2020");
|
||||
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
|
||||
|
||||
$output = NodaTimeSplitter::attempt_splitting("Vor 2020");
|
||||
self::assertEquals($output, [
|
||||
0 => "?",
|
||||
1 => "2019",
|
||||
2 => "00",
|
||||
3 => "00",
|
||||
4 => "+",
|
||||
5 => "Vor",
|
||||
]);
|
||||
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Vor 2020");
|
||||
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
|
||||
|
||||
$output = NodaTimeSplitter::attempt_splitting("Nach Januar 2020");
|
||||
self::assertEquals($output, [
|
||||
0 => "2020",
|
||||
|
|
Loading…
Reference in New Issue
Block a user