From 830b37f5473eaf5803e37255eb3f56278074e30b Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Sat, 26 Sep 2020 16:10:26 +0200 Subject: [PATCH] Improve autotranslating of times before 1.1.1000 --- src/NodaTimeAutotranslater.php | 4 +++- tests/NodaTimeAutotranslaterTest.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/NodaTimeAutotranslater.php b/src/NodaTimeAutotranslater.php index 21945a5..cc01792 100644 --- a/src/NodaTimeAutotranslater.php +++ b/src/NodaTimeAutotranslater.php @@ -669,6 +669,8 @@ final class NodaTimeAutotranslater { return self::translateYearsWithSuffix($timeInfo); } + $suffixMode = self::getSuffixModeForYearsWSuffix((intval($timeInfo['zeit_beginn']) - 1), intval($timeInfo['zeit_ende'])); + if (trim((string)$timeInfo['zeit_zaehlzeit_tag'], ", .0") === "") { $dateStr = "{$timeInfo['zeit_zaehlzeit_jahr']}-{$timeInfo['zeit_zaehlzeit_monat']}-05 00:00:01"; $usecase = self::USECASE_MONTH; @@ -690,7 +692,7 @@ final class NodaTimeAutotranslater { $tLangValue = strftime(getDateFormatByLang($tLang), $dateGeneral ?: 0); } - $output[$tLang] = $tLangValue; + $output[$tLang] = self::applyBcBceFormat($tLang, $tLangValue, $suffixMode); } diff --git a/tests/NodaTimeAutotranslaterTest.php b/tests/NodaTimeAutotranslaterTest.php index 0f206e3..afc4720 100644 --- a/tests/NodaTimeAutotranslaterTest.php +++ b/tests/NodaTimeAutotranslaterTest.php @@ -53,7 +53,7 @@ final class NodaTimeAutotranslaterTest extends TestCase { "zeit_zaehlzeit_tag" => "01", ]; $output = NodaTimeAutotranslater::getTranslations($timeInfo); - self::assertEquals($output["de"], "01.05.20"); + self::assertEquals($output["de"], "01.05.20 n. Chr."); }