Improve splitting and translating of times BC

This commit is contained in:
Joshua Ramon Enslin 2020-09-24 17:35:40 +02:00 committed by Stefan Rohde-Enslin
parent 785b1c5156
commit 9f39437c6e
2 changed files with 47 additions and 18 deletions

View File

@ -208,13 +208,13 @@ final class NodaTimeAutotranslater {
'fa' => 'قرن %s', 'fa' => 'قرن %s',
'fr' => '%sème siècle', 'fr' => '%sème siècle',
'hu' => '%s. század', 'hu' => '%s. század',
'id' => 'abad ke-%s', 'id' => 'Abad ke-%s',
'it' => '%sesimo secolo', 'it' => '%sesimo secolo',
'ka' => 'მე -%s საუკუნე', 'ka' => 'მე -%s საუკუნე',
'ko' => '%s 세기', 'ko' => '%s 세기',
'pl' => '%s wiek', 'pl' => '%s wiek',
'pt' => 'século %s', 'pt' => 'Século %s',
'ro' => 'secolul al %s-lea', 'ro' => 'Secolul al %s-lea',
'ru' => '%s век', 'ru' => '%s век',
'ta' => '%s ஆம் நூற்றாண்டு', 'ta' => '%s ஆம் நூற்றாண்டு',
'tl' => 'Ika-%s na siglo', 'tl' => 'Ika-%s na siglo',
@ -231,13 +231,13 @@ final class NodaTimeAutotranslater {
'fa' => 'قرن %s-%s', 'fa' => 'قرن %s-%s',
'fr' => '%s-%sème siècle', 'fr' => '%s-%sème siècle',
'hu' => '%s.-%s. század', 'hu' => '%s.-%s. század',
'id' => 'abad ke-%s-%s', 'id' => 'Abad ke-%s-%s',
'it' => '%s-%sesimo secolo', 'it' => '%s-%sesimo secolo',
'ka' => 'მე -%s-%s საუკუნე', 'ka' => 'მე -%s-%s საუკუნე',
'ko' => '%s-%s 세기', 'ko' => '%s-%s 세기',
'pl' => '%s-%s wiek', 'pl' => '%s-%s wiek',
'pt' => 'século %s-%s', 'pt' => 'Século %s-%s',
'ro' => 'secolul al %s-%s-lea', 'ro' => 'Secolul al %s-%s-lea',
'ru' => '%s-%s век', 'ru' => '%s-%s век',
'ta' => '%s-%s ஆம் நூற்றாண்டு', 'ta' => '%s-%s ஆம் நூற்றாண்டு',
'tl' => 'Ika-%s hanggang ika-%s na siglo', 'tl' => 'Ika-%s hanggang ika-%s na siglo',
@ -332,7 +332,9 @@ final class NodaTimeAutotranslater {
return self::TRANSLATABLE_NOT; return self::TRANSLATABLE_NOT;
} }
if (intval($zeit_ende) % 100 === 0 and (intval($zeit_beginn) - 1) % 100 === 0) { if (($zeit_ende > 0 && intval($zeit_ende) % 100 === 0 and (intval($zeit_beginn) - 1) % 100 === 0)
|| (intval($zeit_beginn) < 0 && intval($zeit_beginn) % 100 === 0 and (intval($zeit_ende) + 1) % 100 === 0)
) {
return self::TRANSLATABLE_CENTURY; return self::TRANSLATABLE_CENTURY;
} }
@ -481,10 +483,18 @@ final class NodaTimeAutotranslater {
*/ */
public static function translateYearsAsCentury(array $timeInfo):array { public static function translateYearsAsCentury(array $timeInfo):array {
// Beginn: 1500. (1501 - 1) / 100 + 1 = 16. 16th century is the time. if (intval($timeInfo['zeit_beginn']) > 0) {
$start_cen = ((intval($timeInfo['zeit_beginn']) - 1) / 100) + 1; // Beginn: 1500. (1501 - 1) / 100 + 1 = 16. 16th century is the time.
// End: 1600. 16th century is the time. $start_cen = ((intval($timeInfo['zeit_beginn']) - 1) / 100) + 1;
$end_cen = (intval($timeInfo['zeit_ende']) / 100); // End: 1600. 16th century is the time.
$end_cen = (intval($timeInfo['zeit_ende']) / 100);
}
else {
// End: -1600. 16th century is the time.
$start_cen = (intval($timeInfo['zeit_beginn']) / 100);
// End: -1500. (1501 - 1) / 100 + 1 = 16. 16th century is the time.
$end_cen = ((intval($timeInfo['zeit_ende']) + 1) / 100) - 1;
}
$suffixMode = self::getSuffixModeForYearsWSuffix((intval($timeInfo['zeit_beginn']) - 1), intval($timeInfo['zeit_ende'])); $suffixMode = self::getSuffixModeForYearsWSuffix((intval($timeInfo['zeit_beginn']) - 1), intval($timeInfo['zeit_ende']));
@ -492,13 +502,13 @@ final class NodaTimeAutotranslater {
if ($start_cen === $end_cen) { if ($start_cen === $end_cen) {
foreach (self::LANGS_CENTURY_FORMAT as $tLang => $format) { foreach (self::LANGS_CENTURY_FORMAT as $tLang => $format) {
$tLangValue = sprintf($format, (string)$start_cen); $tLangValue = sprintf($format, (string)abs($start_cen));
$output[$tLang] = self::applyBcBceFormat($tLang, $tLangValue, $suffixMode); $output[$tLang] = self::applyBcBceFormat($tLang, $tLangValue, $suffixMode);
} }
} }
else { else {
foreach (self::LANGS_CENTURIES_FORMAT as $tLang => $format) { foreach (self::LANGS_CENTURIES_FORMAT as $tLang => $format) {
$tLangValue = sprintf($format, (string)$start_cen, (string)$end_cen); $tLangValue = sprintf($format, (string)abs($start_cen), (string)abs($end_cen));
$output[$tLang] = self::applyBcBceFormat($tLang, $tLangValue, $suffixMode); $output[$tLang] = self::applyBcBceFormat($tLang, $tLangValue, $suffixMode);
} }
} }

View File

@ -378,9 +378,18 @@ final class NodaTimeSplitter {
$datum = self::clean_input($datum); $datum = self::clean_input($datum);
if (preg_match("/^Kr\.\ e\.\ [0-9][0-9][0-9][0-9]$/", $datum)) { if (preg_match("/^Kr\.\ e\.\ /", $datum)) {
$start = "-" . substr($datum, 7, 4); if ($output = self::attempt_splitting(substr($datum, 7))) {
return [$start, $start, "00", "00", "-"]; $start = strval(-1 * intval($output[1]));
$end = strval(-1 * intval($output[0]));
return [$start, $end, $output[2], $output[3], '-'];
}
}
if (preg_match("/^[0-9][0-9][0-9][0-9]\-től(\ |\-)[0-9][0-9][0-9][0-9]\-ig$/", $datum)) {
$start = substr($datum, 0, 4);
$end = substr($datum, -7, 4);
return [$start, $end, "00", "00", "+", ""];
} }
if (self::stri_occurs($datum, self::STOP_STRINGS_HUNGARIAN)) { if (self::stri_occurs($datum, self::STOP_STRINGS_HUNGARIAN)) {
@ -502,23 +511,33 @@ final class NodaTimeSplitter {
$end = substr($datum, -4); $end = substr($datum, -4);
return [$start, $end, "00", "00", "+", ""]; return [$start, $end, "00", "00", "+", ""];
} }
// 303-305 (n. Chr.)
if (preg_match("/^[0-9][0-9][0-9]\-[0-9][0-9][0-9]$/", $datum)) { // Hungarian Y-m if (preg_match("/^[0-9][0-9][0-9]\-[0-9][0-9][0-9]$/", $datum)) { // Hungarian Y-m
$start = substr($datum, 0, 3); $start = substr($datum, 0, 3);
$end = substr($datum, -3); $end = substr($datum, -3);
if ($end > $start) return ["0" . $start, "0" . $end, "00", "00", "+", ""]; if ($end > $start) return ["0" . $start, "0" . $end, "00", "00", "+", ""];
} }
// 20-30 (n. Chr.)
if (preg_match("/^[0-9][0-9]\-[0-9][0-9]$/", $datum)) { // 20-40 (n. Chr.) if (preg_match("/^[0-9][0-9]\-[0-9][0-9]$/", $datum)) { // 20-40 (n. Chr.)
$start = substr($datum, 0, 2); $start = substr($datum, 0, 2);
$end = substr($datum, -2); $end = substr($datum, -2);
if ($end > $start) return ["00" . $start, "00" . $end, "00", "00", "+", ""]; if ($end > $start) return ["00" . $start, "00" . $end, "00", "00", "+", ""];
} }
// 1920
if (preg_match("/^[0-9][0-9][0-9][0-9]$/", $datum)) { if (preg_match("/^[0-9][0-9][0-9][0-9]$/", $datum)) {
$start = substr($datum, 0, 4); $start = substr($datum, 0, 4);
return [$start, $start, "00", "00", "+", ""]; return [$start, $start, "00", "00", "+", ""];
} }
// 1920
if (preg_match("/^[0-9][0-9][0-9]$/", $datum)) {
$start = "0" . substr($datum, 0, 3);
return [$start, $start, "00", "00", "+", ""];
}
return []; return [];
} }