Improve splitting and translating of times BC
This commit is contained in:
parent
785b1c5156
commit
9f39437c6e
@ -208,13 +208,13 @@ final class NodaTimeAutotranslater {
|
||||
'fa' => 'قرن %s',
|
||||
'fr' => '%sème siècle',
|
||||
'hu' => '%s. század',
|
||||
'id' => 'abad ke-%s',
|
||||
'id' => 'Abad ke-%s',
|
||||
'it' => '%sesimo secolo',
|
||||
'ka' => 'მე -%s საუკუნე',
|
||||
'ko' => '%s 세기',
|
||||
'pl' => '%s wiek',
|
||||
'pt' => 'século %s',
|
||||
'ro' => 'secolul al %s-lea',
|
||||
'pt' => 'Século %s',
|
||||
'ro' => 'Secolul al %s-lea',
|
||||
'ru' => '%s век',
|
||||
'ta' => '%s ஆம் நூற்றாண்டு',
|
||||
'tl' => 'Ika-%s na siglo',
|
||||
@ -231,13 +231,13 @@ final class NodaTimeAutotranslater {
|
||||
'fa' => 'قرن %s-%s',
|
||||
'fr' => '%s-%sème siècle',
|
||||
'hu' => '%s.-%s. század',
|
||||
'id' => 'abad ke-%s-%s',
|
||||
'id' => 'Abad ke-%s-%s',
|
||||
'it' => '%s-%sesimo secolo',
|
||||
'ka' => 'მე -%s-%s საუკუნე',
|
||||
'ko' => '%s-%s 세기',
|
||||
'pl' => '%s-%s wiek',
|
||||
'pt' => 'século %s-%s',
|
||||
'ro' => 'secolul al %s-%s-lea',
|
||||
'pt' => 'Século %s-%s',
|
||||
'ro' => 'Secolul al %s-%s-lea',
|
||||
'ru' => '%s-%s век',
|
||||
'ta' => '%s-%s ஆம் நூற்றாண்டு',
|
||||
'tl' => 'Ika-%s hanggang ika-%s na siglo',
|
||||
@ -332,7 +332,9 @@ final class NodaTimeAutotranslater {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -481,10 +483,18 @@ final class NodaTimeAutotranslater {
|
||||
*/
|
||||
public static function translateYearsAsCentury(array $timeInfo):array {
|
||||
|
||||
// Beginn: 1500. (1501 - 1) / 100 + 1 = 16. 16th century is the time.
|
||||
$start_cen = ((intval($timeInfo['zeit_beginn']) - 1) / 100) + 1;
|
||||
// End: 1600. 16th century is the time.
|
||||
$end_cen = (intval($timeInfo['zeit_ende']) / 100);
|
||||
if (intval($timeInfo['zeit_beginn']) > 0) {
|
||||
// Beginn: 1500. (1501 - 1) / 100 + 1 = 16. 16th century is the time.
|
||||
$start_cen = ((intval($timeInfo['zeit_beginn']) - 1) / 100) + 1;
|
||||
// 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']));
|
||||
|
||||
@ -492,13 +502,13 @@ final class NodaTimeAutotranslater {
|
||||
|
||||
if ($start_cen === $end_cen) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -378,9 +378,18 @@ final class NodaTimeSplitter {
|
||||
|
||||
$datum = self::clean_input($datum);
|
||||
|
||||
if (preg_match("/^Kr\.\ e\.\ [0-9][0-9][0-9][0-9]$/", $datum)) {
|
||||
$start = "-" . substr($datum, 7, 4);
|
||||
return [$start, $start, "00", "00", "-"];
|
||||
if (preg_match("/^Kr\.\ e\.\ /", $datum)) {
|
||||
if ($output = self::attempt_splitting(substr($datum, 7))) {
|
||||
$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)) {
|
||||
@ -502,23 +511,33 @@ final class NodaTimeSplitter {
|
||||
$end = substr($datum, -4);
|
||||
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
|
||||
$start = substr($datum, 0, 3);
|
||||
$end = substr($datum, -3);
|
||||
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.)
|
||||
$start = substr($datum, 0, 2);
|
||||
$end = substr($datum, -2);
|
||||
if ($end > $start) return ["00" . $start, "00" . $end, "00", "00", "+", ""];
|
||||
}
|
||||
|
||||
// 1920
|
||||
if (preg_match("/^[0-9][0-9][0-9][0-9]$/", $datum)) {
|
||||
|
||||
$start = substr($datum, 0, 4);
|
||||
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 [];
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user