diff --git a/src/NodaTimeAutotranslater.php b/src/NodaTimeAutotranslater.php index 3f7a9b3..21945a5 100644 --- a/src/NodaTimeAutotranslater.php +++ b/src/NodaTimeAutotranslater.php @@ -342,7 +342,9 @@ final class NodaTimeAutotranslater { 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; } if ($zeit_ende === $zeit_beginn and trim($zeit_zaehlzeit_monat, ", .0") === "") { diff --git a/src/NodaTimeSplitter.php b/src/NodaTimeSplitter.php index 1930e00..a3fb05e 100644 --- a/src/NodaTimeSplitter.php +++ b/src/NodaTimeSplitter.php @@ -492,19 +492,32 @@ final class NodaTimeSplitter { 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); $month = "0" . substr($datum, 3, 1); $day = substr($datum, 0, 2); 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); $month = substr($datum, 2, 2); $day = "0" . substr($datum, 0, 1); 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); $month = "0" . substr($datum, 2, 1); $day = "0" . substr($datum, 0, 1); diff --git a/tests/NodaTimeAutotranslaterTest.php b/tests/NodaTimeAutotranslaterTest.php index cdd1247..0f206e3 100644 --- a/tests/NodaTimeAutotranslaterTest.php +++ b/tests/NodaTimeAutotranslaterTest.php @@ -35,6 +35,50 @@ final class NodaTimeAutotranslaterTest extends TestCase { } + /** + * Test to check whether the HTML page is correctly generated. + * + * @author Joshua Ramon Enslin + * @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 + * @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. * @@ -167,6 +211,28 @@ final class NodaTimeAutotranslaterTest extends TestCase { } + /** + * Test to check whether the HTML page is correctly generated. + * + * @author Joshua Ramon Enslin + * @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. * diff --git a/tests/NodaTimeSplitterTest.php b/tests/NodaTimeSplitterTest.php index b0e1921..9901c96 100644 --- a/tests/NodaTimeSplitterTest.php +++ b/tests/NodaTimeSplitterTest.php @@ -24,6 +24,54 @@ final class NodaTimeSplitterTest extends TestCase { */ 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"); self::assertEquals($output, [ 0 => "2020",