Allow autotranslation of time spans before 1000 CE
This commit is contained in:
parent
0f6a6ebc84
commit
a4a94a8f8a
|
@ -264,10 +264,10 @@ final class NodaTimeAutotranslater {
|
|||
*/
|
||||
public static function check_translatability(string $zeit_beginn, string $zeit_ende, string $zeit_zaehlzeit_monat):int {
|
||||
|
||||
if (intval($zeit_beginn) > 1000 and $zeit_ende === "?") {
|
||||
if ($zeit_ende === "?") {
|
||||
return self::TRANSLATABLE_SINCE_START;
|
||||
}
|
||||
if (intval($zeit_ende) > 1000 and $zeit_beginn === "?") {
|
||||
if ($zeit_beginn === "?") {
|
||||
return self::TRANSLATABLE_UNTIL_END;
|
||||
}
|
||||
|
||||
|
@ -347,7 +347,7 @@ final class NodaTimeAutotranslater {
|
|||
*
|
||||
* @return array<string>
|
||||
*/
|
||||
public function translateYearsWithSuffix(array $timeInfo):array {
|
||||
public static function translateYearsWithSuffix(array $timeInfo):array {
|
||||
|
||||
$start = intval($timeInfo['zeit_beginn']);
|
||||
$end = intval($timeInfo['zeit_ende']);
|
||||
|
|
|
@ -227,11 +227,11 @@ final class NodaTimeSplitter {
|
|||
public static function timePartsToCountingYear(array $moda):int {
|
||||
|
||||
if ($moda[0] === "?") {
|
||||
return intval($moda[1]);
|
||||
return abs(intval($moda[1]));
|
||||
}
|
||||
|
||||
if ($moda[1] === "?") {
|
||||
return intval($moda[0]);
|
||||
return abs(intval($moda[0]));
|
||||
}
|
||||
|
||||
return abs((int)ceil(intval($moda[1]) - ((intval($moda[1]) - intval($moda[0])) / 2)));
|
||||
|
@ -307,27 +307,34 @@ final class NodaTimeSplitter {
|
|||
|
||||
$datum = self::clean_input($datum);
|
||||
|
||||
if (preg_match("/^[0-9][0-9][0-9][0-9](\-|\/)[0-9][0-9][0-9][0-9] v\. Chr\.$/", $datum)) {
|
||||
if (preg_match("/^[0-9][0-9][0-9]\ v\. Chr\.$/", $datum)) {
|
||||
$start = "-0" . substr($datum, 0, 3);
|
||||
return [$start, $start, "00", "00", "-", ""];
|
||||
}
|
||||
|
||||
if (preg_match("/^[0-9][0-9][0-9][0-9](\-|\/)[0-9][0-9][0-9][0-9]\ v\. Chr\.$/", $datum)) {
|
||||
$start = "-" . substr($datum, 0, 4);
|
||||
$end = "-" . substr($datum, 5, 4);
|
||||
return [$start, $end, "00", "00", "-", ""];
|
||||
}
|
||||
if (preg_match("/^[0-9][0-9][0-9][0-9](\-|\/)[0-9][0-9][0-9] v\. Chr\.$/", $datum)) {
|
||||
if (preg_match("/^[0-9][0-9][0-9][0-9](\-|\/)[0-9][0-9][0-9]\ v\. Chr\.$/", $datum)) {
|
||||
$start = "-" . substr($datum, 0, 4);
|
||||
$end = "-" . substr($datum, 5, 3);
|
||||
return [$start, $end, "00", "00", "-", ""];
|
||||
}
|
||||
if (preg_match("/^[0-9][0-9][0-9](\-|\/)[0-9][0-9][0-9] v\. Chr\.$/", $datum)) {
|
||||
if (preg_match("/^[0-9][0-9][0-9](\-|\/)[0-9][0-9][0-9]\ v\. Chr\.$/", $datum)) {
|
||||
$start = "-" . substr($datum, 0, 3);
|
||||
$end = "-" . substr($datum, 4, 3);
|
||||
return [$start, $end, "00", "00", "-", ""];
|
||||
}
|
||||
if (preg_match("/^[0-9][0-9](\-|\/)[0-9][0-9] v\. Chr\.$/", $datum)) {
|
||||
if (preg_match("/^[0-9][0-9](\-|\/)[0-9][0-9]\ v\. Chr\.$/", $datum)) {
|
||||
$start = "-00" . substr($datum, 0, 2);
|
||||
$end = "-00" . substr($datum, 3, 2);
|
||||
return [$start, $end, "00", "00", "-", ""];
|
||||
}
|
||||
|
||||
$datum = str_replace(". ", ".", $datum);
|
||||
|
||||
if (self::stri_occurs($datum, self::STOP_STRINGS_GERMAN)) {
|
||||
return [];
|
||||
}
|
||||
|
@ -640,6 +647,34 @@ final class NodaTimeSplitter {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an input date is a decade.
|
||||
*
|
||||
* @param string $datum Input date.
|
||||
*
|
||||
* @return array<string>
|
||||
*/
|
||||
public static function is_decade(string $datum):array {
|
||||
|
||||
$datum = self::clean_input($datum);
|
||||
$bcBceIndicator = '+';
|
||||
|
||||
if (preg_match("/^[0-9]0(er\ Jahre)$/", $datum)) {
|
||||
$start = "19" . substr($datum, 0, 2);
|
||||
$ende = (string)(intval($start) + 9);
|
||||
return [$start, $ende, "00", "00", $bcBceIndicator, ""];
|
||||
}
|
||||
|
||||
if (preg_match("/^[0-9][0-9][0-9]0(er\ Jahre)$/", $datum)) {
|
||||
$start = substr($datum, 0, 4);
|
||||
$ende = (string)(intval($start) + 9);
|
||||
return [$start, $ende, "00", "00", $bcBceIndicator, ""];
|
||||
}
|
||||
|
||||
return [];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper to check if any splitting command works.
|
||||
*
|
||||
|
@ -654,6 +689,7 @@ final class NodaTimeSplitter {
|
|||
if (!$moda) $moda = NodaTimeSplitter::is_valid_date($datum);
|
||||
if (!$moda) $moda = NodaTimeSplitter::is_valid_date_hungarian($datum);
|
||||
if (!$moda) $moda = NodaTimeSplitter::is_century($datum);
|
||||
if (!$moda) $moda = NodaTimeSplitter::is_decade($datum);
|
||||
|
||||
return $moda;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user