Allow automatic translations of days before 1000 CE

This commit is contained in:
Joshua Ramon Enslin 2020-09-26 16:02:18 +02:00 committed by Stefan Rohde-Enslin
parent b405855fc2
commit c9d8d4bdbd
4 changed files with 133 additions and 4 deletions

View File

@ -342,7 +342,9 @@ final class NodaTimeAutotranslater {
return self::TRANSLATABLE_DECADE; return self::TRANSLATABLE_DECADE;
} }
if (intval($zeit_ende) < 0 && intval($zeit_beginn) < 0 || intval($zeit_ende) < 1000) { if (intval($zeit_ende) < 0 && intval($zeit_beginn) < 0
|| (intval($zeit_ende) < 1000 and trim($zeit_zaehlzeit_monat, ", .0") === "")
) {
return self::TRANSLATABLE_AS_YEAR_WITH_SUFFIX; return self::TRANSLATABLE_AS_YEAR_WITH_SUFFIX;
} }
if ($zeit_ende === $zeit_beginn and trim($zeit_zaehlzeit_monat, ", .0") === "") { if ($zeit_ende === $zeit_beginn and trim($zeit_zaehlzeit_monat, ", .0") === "") {

View File

@ -492,19 +492,32 @@ final class NodaTimeSplitter {
return [$start, $end, "00", "00", "+", ""]; return [$start, $end, "00", "00", "+", ""];
} }
if (preg_match("/^[0-9][0-9]\.[0-9]\.[0-9][0-9][0-9][0-9]$/", $datum)) { // German T.MM.JJJJ // German TT.MM.JJJJ / TT.MM.JJJ / TT.MM.JJ / TT.MM.J
if (preg_match("/^[0-9][0-9]\.[0-9][0-9]\.([0-9][0-9][0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9]|[0-9])$/", $datum)) { // German T.MM.JJJJ
$start = substr($datum, 6, 4);
$month = substr($datum, 3, 2);
$day = substr($datum, 0, 2);
return [$start, $start, $month, $day, "+", ""];
}
// German TT.M.JJJJ / TT.M.JJJ / TT.M.JJ / TT.M.J
if (preg_match("/^[0-9][0-9]\.[0-9]\.([0-9][0-9][0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9]|[0-9])$/", $datum)) { // German T.MM.JJJJ
$start = substr($datum, 5, 4); $start = substr($datum, 5, 4);
$month = "0" . substr($datum, 3, 1); $month = "0" . substr($datum, 3, 1);
$day = substr($datum, 0, 2); $day = substr($datum, 0, 2);
return [$start, $start, $month, $day, "+", ""]; return [$start, $start, $month, $day, "+", ""];
} }
if (preg_match("/^[0-9]\.[0-9][0-9]\.[0-9][0-9][0-9][0-9]$/", $datum)) { // German T.MM.JJJJ
// German T.MM.JJJJ / T.MM.JJJ / T.MM.JJ / T.MM.J
if (preg_match("/^[0-9]\.[0-9][0-9]\.([0-9][0-9][0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9]|[0-9])$/", $datum)) {
$start = substr($datum, 5, 4); $start = substr($datum, 5, 4);
$month = substr($datum, 2, 2); $month = substr($datum, 2, 2);
$day = "0" . substr($datum, 0, 1); $day = "0" . substr($datum, 0, 1);
return [$start, $start, $month, $day, "+", ""]; return [$start, $start, $month, $day, "+", ""];
} }
if (preg_match("/^[0-9]\.[0-9]\.[0-9][0-9][0-9][0-9]$/", $datum)) { // German T.M.JJJJ
// German T.M.JJJJ / T.M.JJJ / T.M.JJ / T.M.J
if (preg_match("/^[0-9]\.[0-9]\.([0-9][0-9][0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9]|[0-9])$/", $datum)) {
$start = substr($datum, 4, 4); $start = substr($datum, 4, 4);
$month = "0" . substr($datum, 2, 1); $month = "0" . substr($datum, 2, 1);
$day = "0" . substr($datum, 0, 1); $day = "0" . substr($datum, 0, 1);

View File

@ -35,6 +35,50 @@ final class NodaTimeAutotranslaterTest extends TestCase {
} }
/**
* Test to check whether the HTML page is correctly generated.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
* @group ValidOutput
*
* @return void
*/
public function testCanTranslateSingleDayWith2DigitYear():void {
$timeInfo = [
"zeit_beginn" => "20",
"zeit_ende" => "20",
"zeit_zaehlzeit_jahr" => "0020",
"zeit_zaehlzeit_monat" => "05",
"zeit_zaehlzeit_tag" => "01",
];
$output = NodaTimeAutotranslater::getTranslations($timeInfo);
self::assertEquals($output["de"], "01.05.20");
}
/**
* Test to check whether the HTML page is correctly generated.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
* @group ValidOutput
*
* @return void
*/
public function testCanTranslateSingleDayWith2DigitYearBeforeCommonEra():void {
$timeInfo = [
"zeit_beginn" => "-20",
"zeit_ende" => "-20",
"zeit_zaehlzeit_jahr" => "0020",
"zeit_zaehlzeit_monat" => "05",
"zeit_zaehlzeit_tag" => "01",
];
$output = NodaTimeAutotranslater::getTranslations($timeInfo);
self::assertEquals($output["de"], "01.05.20 v. Chr.");
}
/** /**
* Test to check whether the HTML page is correctly generated. * Test to check whether the HTML page is correctly generated.
* *
@ -167,6 +211,28 @@ final class NodaTimeAutotranslaterTest extends TestCase {
} }
/**
* Test to check whether the HTML page is correctly generated.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
* @group ValidOutput
*
* @return void
*/
public function testTranslateDecadeBeforeCommonEraAsTimespan4Digits():void {
$timeInfo = [
"zeit_beginn" => "-1910",
"zeit_ende" => "-1901",
"zeit_zaehlzeit_jahr" => "0005",
"zeit_zaehlzeit_monat" => "00",
"zeit_zaehlzeit_tag" => "00",
];
$output = NodaTimeAutotranslater::getTranslations($timeInfo);
self::assertEquals($output["de"], "1910-1901 v. Chr.");
}
/** /**
* Test to check whether the HTML page is correctly generated. * Test to check whether the HTML page is correctly generated.
* *

View File

@ -24,6 +24,54 @@ final class NodaTimeSplitterTest extends TestCase {
*/ */
public function testSplitSimpleDatesGerman():void { public function testSplitSimpleDatesGerman():void {
$output = NodaTimeSplitter::attempt_splitting("02.1.25 v. Chr");
self::assertEquals($output, [
0 => "-25",
1 => "-25",
2 => "01",
3 => "02",
4 => "-",
5 => "",
]);
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "02.01.25 v. Chr.");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 25);
$output = NodaTimeSplitter::attempt_splitting("2.01.25 v. Chr");
self::assertEquals($output, [
0 => "-25",
1 => "-25",
2 => "01",
3 => "02",
4 => "-",
5 => "",
]);
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "02.01.25 v. Chr.");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 25);
$output = NodaTimeSplitter::attempt_splitting("02.01.25 v. Chr");
self::assertEquals($output, [
0 => "-25",
1 => "-25",
2 => "01",
3 => "02",
4 => "-",
5 => "",
]);
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "02.01.25 v. Chr.");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 25);
$output = NodaTimeSplitter::attempt_splitting("2.1.25 v. Chr");
self::assertEquals($output, [
0 => "-25",
1 => "-25",
2 => "01",
3 => "02",
4 => "-",
5 => "",
]);
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "02.01.25 v. Chr.");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 25);
$output = NodaTimeSplitter::attempt_splitting("2.1.2020"); $output = NodaTimeSplitter::attempt_splitting("2.1.2020");
self::assertEquals($output, [ self::assertEquals($output, [
0 => "2020", 0 => "2020",