Add test for NodaTimeAutotranslater, allow parsing days and months BC
This commit is contained in:
@ -420,13 +420,25 @@ final class NodaTimeAutotranslater {
|
||||
|
||||
$suffixMode = self::getSuffixModeForYearsWSuffix($start, $end);
|
||||
|
||||
// Time info to pass
|
||||
if ($suffixMode === 2) {
|
||||
$timeInfoToCopy = $timeInfo;
|
||||
$timeInfoToCopy["zeit_beginn"] = abs($start);
|
||||
$timeInfoToCopy["zeit_ende"] = abs($end);
|
||||
}
|
||||
|
||||
$output = [];
|
||||
foreach (self::LANGS_TO_CE_FORMAT as $tLang => $ceFormat) {
|
||||
|
||||
if ($start === $end) {
|
||||
$year = sprintf(self::LANGS_SINGLE_YEAR_FORMAT[$tLang], (string)abs($start));
|
||||
if ($suffixMode === 2) {
|
||||
$year = self::getTranslations($timeInfoToCopy)[$tLang];
|
||||
}
|
||||
else {
|
||||
if ($start === $end) {
|
||||
$year = sprintf(self::LANGS_SINGLE_YEAR_FORMAT[$tLang], (string)abs($start));
|
||||
}
|
||||
else $year = sprintf(self::LANGS_YEARSPAN_FORMAT[$tLang], (string)abs($start), (string)abs($end));
|
||||
}
|
||||
else $year = sprintf(self::LANGS_YEARSPAN_FORMAT[$tLang], (string)abs($start), (string)abs($end));
|
||||
|
||||
$output[$tLang] = self::applyBcBceFormat($tLang, $year, $suffixMode);
|
||||
|
||||
@ -467,6 +479,7 @@ final class NodaTimeAutotranslater {
|
||||
$end = intval($timeInfo['zeit_ende']);
|
||||
$output = [];
|
||||
|
||||
if (abs($start) === 1102) throw new Exception(var_export($timeInfo, true));
|
||||
foreach (self::LANGS_YEARSPAN_FORMAT as $tLang => $format) {
|
||||
$output[$tLang] = sprintf($format, (string)abs($start), (string)abs($end));
|
||||
}
|
||||
@ -615,7 +628,7 @@ final class NodaTimeAutotranslater {
|
||||
public static function getTranslations(array $timeInfo):array {
|
||||
|
||||
if (!($translation_type = self::check_translatability((string)$timeInfo['zeit_beginn'], (string)$timeInfo['zeit_ende'], (string)$timeInfo['zeit_zaehlzeit_monat']))) {
|
||||
throw new MDgenericInvalidInputsException("Non-translatable date");
|
||||
throw new MDgenericInvalidInputsException("Non-translatable date: {$timeInfo['zeit_beginn']} - {$timeInfo['zeit_ende']}");
|
||||
}
|
||||
|
||||
if ($translation_type === self::TRANSLATABLE_ONLY_YEAR) {
|
||||
|
Reference in New Issue
Block a user