Fix wrong assumption on handling counting times when autotranslating

"after <month>"
This commit is contained in:
Joshua Ramon Enslin 2020-10-04 18:36:03 +02:00 committed by Stefan Rohde-Enslin
parent c9a1a74bce
commit be46c39efd
3 changed files with 14 additions and 9 deletions

View File

@ -637,12 +637,6 @@ final class NodaTimeAutotranslater {
if (empty(trim($timeInfo['zeit_zaehlzeit_monat'], " ,.;0"))) { if (empty(trim($timeInfo['zeit_zaehlzeit_monat'], " ,.;0"))) {
$timeInfo['zeit_beginn'] = strval(intval($timeInfo['zeit_beginn']) - 1); $timeInfo['zeit_beginn'] = strval(intval($timeInfo['zeit_beginn']) - 1);
} }
else if (empty(trim($timeInfo['zeit_zaehlzeit_tag'], " ,.;0"))) {
$timeInfo['zeit_zaehlzeit_monat'] = strval(intval($timeInfo['zeit_zaehlzeit_monat']) - 1);
}
else {
$timeInfo['zeit_zaehlzeit_tag'] = strval(intval($timeInfo['zeit_zaehlzeit_tag']) - 1);
}
# else throw new Exception("Unhandled split case. Counting time is: " . var_export($timeInfo, true)); # else throw new Exception("Unhandled split case. Counting time is: " . var_export($timeInfo, true));
$innerTimeInfo = $timeInfo; $innerTimeInfo = $timeInfo;
$innerTimeInfo['zeit_ende'] = $timeInfo['zeit_beginn']; $innerTimeInfo['zeit_ende'] = $timeInfo['zeit_beginn'];

View File

@ -692,6 +692,17 @@ final class NodaTimeSplitter {
return $output; return $output;
} }
} }
if (preg_match("/^[0-9]{4}\ (\(nach)/", $datum)) {
if (($spacePos = strpos($datum, " ")) === false) {
return [];
}
if ($output = self::attempt_splitting(substr($datum, 0, $spacePos))) {
$output[1] = "?";
$output[0] = strval((intval($output[0]) + 1));
$output[5] = "Nach";
return $output;
}
}
if (preg_match("/^(Ab|Seit|seit)\ /", $datum)) { if (preg_match("/^(Ab|Seit|seit)\ /", $datum)) {
if (($spacePos = strpos($datum, " ")) === false) { if (($spacePos = strpos($datum, " ")) === false) {

View File

@ -540,7 +540,7 @@ final class NodaTimeAutotranslaterTest extends TestCase {
public function testCanTranslateAfterSingleMonth():void { public function testCanTranslateAfterSingleMonth():void {
$timeInfo = [ $timeInfo = [
"zeit_name" => "Nach April 1920", "zeit_name" => "Nach Mai 1920",
"zeit_beginn" => "1920", "zeit_beginn" => "1920",
"zeit_ende" => "?", "zeit_ende" => "?",
"zeit_zaehlzeit_jahr" => "1920", "zeit_zaehlzeit_jahr" => "1920",
@ -548,7 +548,7 @@ final class NodaTimeAutotranslaterTest extends TestCase {
"zeit_zaehlzeit_tag" => "00", "zeit_zaehlzeit_tag" => "00",
]; ];
$output = NodaTimeAutotranslater::getTranslations($timeInfo); $output = NodaTimeAutotranslater::getTranslations($timeInfo);
self::assertEquals($output["de"], "Nach April 1920"); self::assertEquals($output["de"], "Nach Mai 1920");
} }
@ -568,7 +568,7 @@ final class NodaTimeAutotranslaterTest extends TestCase {
"zeit_ende" => "?", "zeit_ende" => "?",
"zeit_zaehlzeit_jahr" => "1919", "zeit_zaehlzeit_jahr" => "1919",
"zeit_zaehlzeit_monat" => "12", "zeit_zaehlzeit_monat" => "12",
"zeit_zaehlzeit_tag" => "02", "zeit_zaehlzeit_tag" => "01",
]; ];
$output = NodaTimeAutotranslater::getTranslations($timeInfo); $output = NodaTimeAutotranslater::getTranslations($timeInfo);
self::assertEquals($output["de"], "Nach 01.12.1919"); self::assertEquals($output["de"], "Nach 01.12.1919");