Add tests for German dates, enable splitting of 5 digit timespans
This commit is contained in:
parent
14b0d8037d
commit
3058f25a1c
|
@ -431,7 +431,11 @@ final class NodaTimeAutotranslater {
|
||||||
foreach (self::LANGS_TO_CE_FORMAT as $tLang => $ceFormat) {
|
foreach (self::LANGS_TO_CE_FORMAT as $tLang => $ceFormat) {
|
||||||
|
|
||||||
if ($suffixMode === 2) {
|
if ($suffixMode === 2) {
|
||||||
|
$ceIndicatorsToRemove = explode("%s", self::LANGS_TO_CE_FORMAT[$tLang]);
|
||||||
$year = self::getTranslations($timeInfoToCopy)[$tLang];
|
$year = self::getTranslations($timeInfoToCopy)[$tLang];
|
||||||
|
foreach ($ceIndicatorsToRemove as $ceIndicatorToRemove) {
|
||||||
|
$year = str_replace($ceIndicatorToRemove, "", $year);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ($start === $end) {
|
if ($start === $end) {
|
||||||
|
|
|
@ -330,7 +330,7 @@ final class NodaTimeSplitter {
|
||||||
$end = $start;
|
$end = $start;
|
||||||
$start = $startToSet;
|
$start = $startToSet;
|
||||||
}
|
}
|
||||||
return [$start, $end, $output[2], $output[3], '-'];
|
return [$start, $end, $output[2], $output[3], '-', ""];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -469,6 +469,13 @@ final class NodaTimeSplitter {
|
||||||
|
|
||||||
$datum = self::clean_input($datum);
|
$datum = self::clean_input($datum);
|
||||||
|
|
||||||
|
// 10000-20000
|
||||||
|
if (!empty(preg_match("/^[0-9][0-9][0-9][0-9][0-9](\-|\/)[0-9][0-9][0-9][0-9][0-9]$/", $datum))) {
|
||||||
|
$start = substr($datum, 0, 5);
|
||||||
|
$end = substr($datum, 6, 5);
|
||||||
|
return [$start, $end, "00", "00", "+", ""];
|
||||||
|
}
|
||||||
|
|
||||||
// 0000-0000
|
// 0000-0000
|
||||||
if (!empty(preg_match("/^[0-9][0-9][0-9][0-9](\-|\/)[0-9][0-9][0-9][0-9]$/", $datum))
|
if (!empty(preg_match("/^[0-9][0-9][0-9][0-9](\-|\/)[0-9][0-9][0-9][0-9]$/", $datum))
|
||||||
|| !empty(preg_match("/^[0-9][0-9][0-9][0-9](\-|\/)[0-9][0-9][0-9][0-9]\.$/", $datum))
|
|| !empty(preg_match("/^[0-9][0-9][0-9][0-9](\-|\/)[0-9][0-9][0-9][0-9]\.$/", $datum))
|
||||||
|
|
|
@ -255,6 +255,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 testCanTranslateSingleThreeDigitYearBeforeCommonEra():void {
|
||||||
|
|
||||||
|
$timeInfo = [
|
||||||
|
"zeit_beginn" => "-100",
|
||||||
|
"zeit_ende" => "-100",
|
||||||
|
"zeit_zaehlzeit_jahr" => "100",
|
||||||
|
"zeit_zaehlzeit_monat" => "00",
|
||||||
|
"zeit_zaehlzeit_tag" => "00",
|
||||||
|
];
|
||||||
|
$output = NodaTimeAutotranslater::getTranslations($timeInfo);
|
||||||
|
self::assertEquals($output["de"], "100 v. Chr.");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test to check whether the HTML page is correctly generated.
|
* Test to check whether the HTML page is correctly generated.
|
||||||
*
|
*
|
||||||
|
|
|
@ -14,6 +14,151 @@ require_once __DIR__ . "/../../MD_STD/MD_STD.php";
|
||||||
*/
|
*/
|
||||||
final class NodaTimeSplitterTest extends TestCase {
|
final class NodaTimeSplitterTest 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 testSplitSimpleDatesGerman():void {
|
||||||
|
|
||||||
|
$output = NodaTimeSplitter::attempt_splitting("2.1.2020");
|
||||||
|
self::assertEquals($output, [
|
||||||
|
0 => "2020",
|
||||||
|
1 => "2020",
|
||||||
|
2 => "01",
|
||||||
|
3 => "02",
|
||||||
|
4 => "+",
|
||||||
|
5 => "",
|
||||||
|
]);
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "02.01.2020");
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
|
||||||
|
|
||||||
|
$output = NodaTimeSplitter::attempt_splitting("02.01.2020");
|
||||||
|
self::assertEquals($output, [
|
||||||
|
0 => "2020",
|
||||||
|
1 => "2020",
|
||||||
|
2 => "01",
|
||||||
|
3 => "02",
|
||||||
|
4 => "+",
|
||||||
|
5 => "",
|
||||||
|
]);
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "02.01.2020");
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
|
||||||
|
|
||||||
|
$output = NodaTimeSplitter::attempt_splitting("2. Januar 2020");
|
||||||
|
self::assertEquals($output, [
|
||||||
|
0 => "2020",
|
||||||
|
1 => "2020",
|
||||||
|
2 => "01",
|
||||||
|
3 => "02",
|
||||||
|
4 => "+",
|
||||||
|
5 => "",
|
||||||
|
]);
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "02.01.2020");
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
|
||||||
|
|
||||||
|
$output = NodaTimeSplitter::attempt_splitting("1920-1929");
|
||||||
|
self::assertEquals($output, [
|
||||||
|
0 => "1920",
|
||||||
|
1 => "1929",
|
||||||
|
2 => "00",
|
||||||
|
3 => "00",
|
||||||
|
4 => "+",
|
||||||
|
5 => "",
|
||||||
|
]);
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1920-1929");
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925);
|
||||||
|
|
||||||
|
$output = NodaTimeSplitter::attempt_splitting("1920er Jahre");
|
||||||
|
self::assertEquals($output, [
|
||||||
|
0 => "1920",
|
||||||
|
1 => "1929",
|
||||||
|
2 => "00",
|
||||||
|
3 => "00",
|
||||||
|
4 => "+",
|
||||||
|
5 => "",
|
||||||
|
]);
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1920-1929");
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925);
|
||||||
|
|
||||||
|
$output = NodaTimeSplitter::attempt_splitting("Januar 2020");
|
||||||
|
self::assertEquals($output, [
|
||||||
|
0 => "2020",
|
||||||
|
1 => "2020",
|
||||||
|
2 => "01",
|
||||||
|
3 => "00",
|
||||||
|
4 => "+",
|
||||||
|
5 => "",
|
||||||
|
]);
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Januar 2020");
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
|
||||||
|
|
||||||
|
$output = NodaTimeSplitter::attempt_splitting("Januar 2020 v. Chr.");
|
||||||
|
self::assertEquals($output, [
|
||||||
|
0 => "-2020",
|
||||||
|
1 => "-2020",
|
||||||
|
2 => "01",
|
||||||
|
3 => "00",
|
||||||
|
4 => "-",
|
||||||
|
5 => "",
|
||||||
|
]);
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Januar 2020 v. Chr.");
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
|
||||||
|
|
||||||
|
// 5-Digit timespans BCE
|
||||||
|
$output = NodaTimeSplitter::attempt_splitting("40000-25000 vor Christus");
|
||||||
|
self::assertEquals($output, [
|
||||||
|
0 => "-40000",
|
||||||
|
1 => "-25000",
|
||||||
|
2 => "00",
|
||||||
|
3 => "00",
|
||||||
|
4 => "-",
|
||||||
|
5 => "",
|
||||||
|
]);
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "40000-25000 v. Chr.");
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 32500);
|
||||||
|
|
||||||
|
$output = NodaTimeSplitter::attempt_splitting("20. Jahrhundert v. Chr.");
|
||||||
|
self::assertEquals($output, [
|
||||||
|
0 => "-2000",
|
||||||
|
1 => "-1901",
|
||||||
|
2 => "00",
|
||||||
|
3 => "00",
|
||||||
|
4 => "-",
|
||||||
|
5 => "",
|
||||||
|
]);
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "2000-1901 v. Chr.");
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1950);
|
||||||
|
|
||||||
|
$output = NodaTimeSplitter::attempt_splitting("20.-19. Jahrhundert v. Chr.");
|
||||||
|
self::assertEquals($output, [
|
||||||
|
0 => "-2000",
|
||||||
|
1 => "-1801",
|
||||||
|
2 => "00",
|
||||||
|
3 => "00",
|
||||||
|
4 => "-",
|
||||||
|
5 => "",
|
||||||
|
]);
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "2000-1801 v. Chr.");
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1900);
|
||||||
|
|
||||||
|
$output = NodaTimeSplitter::attempt_splitting("Bis 20.-19. Jahrhundert v. Chr.");
|
||||||
|
self::assertEquals($output, [
|
||||||
|
0 => "?",
|
||||||
|
1 => "-1801",
|
||||||
|
2 => "00",
|
||||||
|
3 => "00",
|
||||||
|
4 => "-",
|
||||||
|
5 => "",
|
||||||
|
]);
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Bis 1801 v. Chr.");
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1801);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test to check whether the HTML page is correctly generated.
|
* Test to check whether the HTML page is correctly generated.
|
||||||
*
|
*
|
||||||
|
@ -34,6 +179,7 @@ final class NodaTimeSplitterTest extends TestCase {
|
||||||
5 => "",
|
5 => "",
|
||||||
]);
|
]);
|
||||||
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "02.01.2020");
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "02.01.2020");
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
|
||||||
|
|
||||||
$output = NodaTimeSplitter::attempt_splitting("2020. Januar 2.");
|
$output = NodaTimeSplitter::attempt_splitting("2020. Januar 2.");
|
||||||
self::assertEquals($output, [
|
self::assertEquals($output, [
|
||||||
|
@ -45,6 +191,7 @@ final class NodaTimeSplitterTest extends TestCase {
|
||||||
5 => "",
|
5 => "",
|
||||||
]);
|
]);
|
||||||
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "02.01.2020");
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "02.01.2020");
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
|
||||||
|
|
||||||
$output = NodaTimeSplitter::attempt_splitting("1920-tól 1929-ig");
|
$output = NodaTimeSplitter::attempt_splitting("1920-tól 1929-ig");
|
||||||
self::assertEquals($output, [
|
self::assertEquals($output, [
|
||||||
|
@ -56,6 +203,7 @@ final class NodaTimeSplitterTest extends TestCase {
|
||||||
5 => "",
|
5 => "",
|
||||||
]);
|
]);
|
||||||
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1920-1929");
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1920-1929");
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925);
|
||||||
|
|
||||||
$output = NodaTimeSplitter::attempt_splitting("1920-1929 között");
|
$output = NodaTimeSplitter::attempt_splitting("1920-1929 között");
|
||||||
self::assertEquals($output, [
|
self::assertEquals($output, [
|
||||||
|
@ -67,6 +215,7 @@ final class NodaTimeSplitterTest extends TestCase {
|
||||||
5 => "",
|
5 => "",
|
||||||
]);
|
]);
|
||||||
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1920-1929");
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1920-1929");
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925);
|
||||||
|
|
||||||
$output = NodaTimeSplitter::attempt_splitting("1920-től 1929-ig");
|
$output = NodaTimeSplitter::attempt_splitting("1920-től 1929-ig");
|
||||||
self::assertEquals($output, [
|
self::assertEquals($output, [
|
||||||
|
@ -78,6 +227,7 @@ final class NodaTimeSplitterTest extends TestCase {
|
||||||
5 => "",
|
5 => "",
|
||||||
]);
|
]);
|
||||||
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1920-1929");
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1920-1929");
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925);
|
||||||
|
|
||||||
$output = NodaTimeSplitter::attempt_splitting("1920-es évek");
|
$output = NodaTimeSplitter::attempt_splitting("1920-es évek");
|
||||||
self::assertEquals($output, [
|
self::assertEquals($output, [
|
||||||
|
@ -89,6 +239,7 @@ final class NodaTimeSplitterTest extends TestCase {
|
||||||
5 => "",
|
5 => "",
|
||||||
]);
|
]);
|
||||||
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1920-1929");
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1920-1929");
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925);
|
||||||
|
|
||||||
$output = NodaTimeSplitter::attempt_splitting("2020. Januar");
|
$output = NodaTimeSplitter::attempt_splitting("2020. Januar");
|
||||||
self::assertEquals($output, [
|
self::assertEquals($output, [
|
||||||
|
@ -100,6 +251,7 @@ final class NodaTimeSplitterTest extends TestCase {
|
||||||
5 => "",
|
5 => "",
|
||||||
]);
|
]);
|
||||||
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Januar 2020");
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Januar 2020");
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
|
||||||
|
|
||||||
$output = NodaTimeSplitter::attempt_splitting("Kr. e. 2020. Januar");
|
$output = NodaTimeSplitter::attempt_splitting("Kr. e. 2020. Januar");
|
||||||
self::assertEquals($output, [
|
self::assertEquals($output, [
|
||||||
|
@ -111,6 +263,7 @@ final class NodaTimeSplitterTest extends TestCase {
|
||||||
5 => "",
|
5 => "",
|
||||||
]);
|
]);
|
||||||
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Januar 2020 v. Chr.");
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Januar 2020 v. Chr.");
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
|
||||||
|
|
||||||
$output = NodaTimeSplitter::attempt_splitting("Kr. e. 20. század");
|
$output = NodaTimeSplitter::attempt_splitting("Kr. e. 20. század");
|
||||||
self::assertEquals($output, [
|
self::assertEquals($output, [
|
||||||
|
@ -122,6 +275,7 @@ final class NodaTimeSplitterTest extends TestCase {
|
||||||
5 => "",
|
5 => "",
|
||||||
]);
|
]);
|
||||||
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "2000-1901 v. Chr.");
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "2000-1901 v. Chr.");
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1950);
|
||||||
|
|
||||||
$output = NodaTimeSplitter::attempt_splitting("Kr. e. 20.-19. század");
|
$output = NodaTimeSplitter::attempt_splitting("Kr. e. 20.-19. század");
|
||||||
self::assertEquals($output, [
|
self::assertEquals($output, [
|
||||||
|
@ -133,6 +287,7 @@ final class NodaTimeSplitterTest extends TestCase {
|
||||||
5 => "",
|
5 => "",
|
||||||
]);
|
]);
|
||||||
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "2000-1801 v. Chr.");
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "2000-1801 v. Chr.");
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1900);
|
||||||
|
|
||||||
$output = NodaTimeSplitter::attempt_splitting("Kr. e. 20.-19. század-ig");
|
$output = NodaTimeSplitter::attempt_splitting("Kr. e. 20.-19. század-ig");
|
||||||
self::assertEquals($output, [
|
self::assertEquals($output, [
|
||||||
|
@ -144,6 +299,7 @@ final class NodaTimeSplitterTest extends TestCase {
|
||||||
5 => "",
|
5 => "",
|
||||||
]);
|
]);
|
||||||
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Bis 1801 v. Chr.");
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Bis 1801 v. Chr.");
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1801);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,6 +328,9 @@ final class NodaTimeSplitterTest extends TestCase {
|
||||||
$output = NodaTimeSplitter::attempt_splitting("Januar-Februar");
|
$output = NodaTimeSplitter::attempt_splitting("Januar-Februar");
|
||||||
self::assertEquals($output, []);
|
self::assertEquals($output, []);
|
||||||
|
|
||||||
|
$output = NodaTimeSplitter::attempt_splitting("Nach 1944");
|
||||||
|
self::assertEquals($output, []);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user