Explicitly use global namespace in function calls

This commit is contained in:
Joshua Ramon Enslin 2020-10-23 17:03:51 +02:00 committed by Stefan Rohde-Enslin
parent 14e82826ae
commit 0ea9c31845
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE
2 changed files with 257 additions and 257 deletions

View File

@ -378,33 +378,33 @@ final class NodaTimeAutotranslater {
return self::TRANSLATABLE_UNTIL_END; return self::TRANSLATABLE_UNTIL_END;
} }
if (intval($zeit_ende) >= 0 && intval($zeit_beginn) < 0) { if (\intval($zeit_ende) >= 0 && \intval($zeit_beginn) < 0) {
return self::TRANSLATABLE_NOT; return self::TRANSLATABLE_NOT;
} }
if (($zeit_ende > 0 && 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) || (\intval($zeit_beginn) < 0 && \intval($zeit_beginn) % 100 === 0 and (\intval($zeit_ende) + 1) % 100 === 0)
) { ) {
return self::TRANSLATABLE_CENTURY; return self::TRANSLATABLE_CENTURY;
} }
if ((intval($zeit_ende) + 1) % 10 === 0 and intval($zeit_beginn) % 10 === 0 and intval($zeit_beginn) > 1000) { if ((\intval($zeit_ende) + 1) % 10 === 0 and \intval($zeit_beginn) % 10 === 0 and \intval($zeit_beginn) > 1000) {
return self::TRANSLATABLE_DECADE; return self::TRANSLATABLE_DECADE;
} }
if (intval($zeit_ende) < 0 && intval($zeit_beginn) < 0 if (\intval($zeit_ende) < 0 && \intval($zeit_beginn) < 0
|| (intval($zeit_ende) < 1000 and trim($zeit_zaehlzeit_monat, ", .0") === "") || (\intval($zeit_ende) < 1000 and \trim($zeit_zaehlzeit_monat, ", .0") === "")
) { ) {
return self::TRANSLATABLE_AS_YEAR_WITH_SUFFIX; return self::TRANSLATABLE_AS_YEAR_WITH_SUFFIX;
} }
if ($zeit_ende === $zeit_beginn and trim($zeit_zaehlzeit_monat, ", .0") === "") { if ($zeit_ende === $zeit_beginn and \trim($zeit_zaehlzeit_monat, ", .0") === "") {
return self::TRANSLATABLE_ONLY_YEAR; return self::TRANSLATABLE_ONLY_YEAR;
} }
if ($zeit_ende !== $zeit_beginn and trim($zeit_zaehlzeit_monat, ", .0") === "") { if ($zeit_ende !== $zeit_beginn and \trim($zeit_zaehlzeit_monat, ", .0") === "") {
return self::TRANSLATABLE_TIMESPAN_YEARS; return self::TRANSLATABLE_TIMESPAN_YEARS;
} }
// Conditions speaking against translatability. // Conditions speaking against translatability.
if (trim($zeit_zaehlzeit_monat, ", .0") === "") { if (\trim($zeit_zaehlzeit_monat, ", .0") === "") {
return self::TRANSLATABLE_NOT; return self::TRANSLATABLE_NOT;
} }
@ -449,9 +449,9 @@ final class NodaTimeAutotranslater {
case 0: case 0:
return $timeName; return $timeName;
case 1: case 1:
return sprintf(self::LANGS_TO_CE_FORMAT[$tLang], $timeName); return \sprintf(self::LANGS_TO_CE_FORMAT[$tLang], $timeName);
case 2: case 2:
return sprintf(self::LANGS_TO_BCE_FORMAT[$tLang], $timeName); return \sprintf(self::LANGS_TO_BCE_FORMAT[$tLang], $timeName);
default: default:
throw new Exception("Unknown case encountered for time translations."); throw new Exception("Unknown case encountered for time translations.");
} }
@ -467,16 +467,16 @@ final class NodaTimeAutotranslater {
*/ */
public static function translateYearsWithSuffix(array $timeInfo):array { public static function translateYearsWithSuffix(array $timeInfo):array {
$start = intval($timeInfo['zeit_beginn']); $start = \intval($timeInfo['zeit_beginn']);
$end = intval($timeInfo['zeit_ende']); $end = \intval($timeInfo['zeit_ende']);
$suffixMode = self::getSuffixModeForYearsWSuffix($start, $end); $suffixMode = self::getSuffixModeForYearsWSuffix($start, $end);
// Time info to pass // Time info to pass
if ($suffixMode === 2) { if ($suffixMode === 2) {
$timeInfoToCopy = $timeInfo; $timeInfoToCopy = $timeInfo;
$timeInfoToCopy["zeit_beginn"] = abs($start); $timeInfoToCopy["zeit_beginn"] = \abs($start);
$timeInfoToCopy["zeit_ende"] = abs($end); $timeInfoToCopy["zeit_ende"] = \abs($end);
} }
$output = []; $output = [];
@ -495,9 +495,9 @@ final class NodaTimeAutotranslater {
} }
else { else {
if ($start === $end) { if ($start === $end) {
$year = sprintf(self::LANGS_SINGLE_YEAR_FORMAT[$tLang], (string)abs($start)); $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); $output[$tLang] = self::applyBcBceFormat($tLang, $year, $suffixMode);
@ -516,11 +516,11 @@ final class NodaTimeAutotranslater {
*/ */
public static function translateYearOnly(array $timeInfo):array { public static function translateYearOnly(array $timeInfo):array {
$start = intval($timeInfo['zeit_beginn']); $start = \intval($timeInfo['zeit_beginn']);
$output = []; $output = [];
foreach (self::LANGS_SINGLE_YEAR_FORMAT as $tLang => $format) { foreach (self::LANGS_SINGLE_YEAR_FORMAT as $tLang => $format) {
$output[$tLang] = sprintf($format, (string)abs($start)); $output[$tLang] = \sprintf($format, (string)\abs($start));
} }
return $output; return $output;
@ -535,13 +535,13 @@ final class NodaTimeAutotranslater {
*/ */
public static function translateTimespanYears(array $timeInfo):array { public static function translateTimespanYears(array $timeInfo):array {
$start = intval($timeInfo['zeit_beginn']); $start = \intval($timeInfo['zeit_beginn']);
$end = intval($timeInfo['zeit_ende']); $end = \intval($timeInfo['zeit_ende']);
$output = []; $output = [];
if (abs($start) === 1102) throw new Exception(var_export($timeInfo, true)); if (\abs($start) === 1102) throw new Exception(var_export($timeInfo, true));
foreach (self::LANGS_YEARSPAN_FORMAT as $tLang => $format) { foreach (self::LANGS_YEARSPAN_FORMAT as $tLang => $format) {
$output[$tLang] = sprintf($format, (string)abs($start), (string)abs($end)); $output[$tLang] = \sprintf($format, (string)\abs($start), (string)\abs($end));
} }
return $output; return $output;
@ -556,32 +556,32 @@ final class NodaTimeAutotranslater {
*/ */
public static function translateYearsAsCentury(array $timeInfo):array { public static function translateYearsAsCentury(array $timeInfo):array {
if (intval($timeInfo['zeit_beginn']) > 0) { if (\intval($timeInfo['zeit_beginn']) > 0) {
// Beginn: 1500. (1501 - 1) / 100 + 1 = 16. 16th century is the time. // Beginn: 1500. (1501 - 1) / 100 + 1 = 16. 16th century is the time.
$start_cen = ((intval($timeInfo['zeit_beginn']) - 1) / 100) + 1; $start_cen = ((\intval($timeInfo['zeit_beginn']) - 1) / 100) + 1;
// End: 1600. 16th century is the time. // End: 1600. 16th century is the time.
$end_cen = (intval($timeInfo['zeit_ende']) / 100); $end_cen = (\intval($timeInfo['zeit_ende']) / 100);
} }
else { else {
// End: -1600. 16th century is the time. // End: -1600. 16th century is the time.
$start_cen = (intval($timeInfo['zeit_beginn']) / 100); $start_cen = (\intval($timeInfo['zeit_beginn']) / 100);
// End: -1500. (1501 - 1) / 100 + 1 = 16. 16th century is the time. // End: -1500. (1501 - 1) / 100 + 1 = 16. 16th century is the time.
$end_cen = ((intval($timeInfo['zeit_ende']) + 1) / 100) - 1; $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']));
$output = []; $output = [];
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)abs($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)abs($start_cen), (string)abs($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);
} }
} }
@ -599,25 +599,25 @@ final class NodaTimeAutotranslater {
public static function translateYearsAsDecade(array $timeInfo):array { public static function translateYearsAsDecade(array $timeInfo):array {
// Beginn: 1500. (1501 - 1) / 100 + 1 = 16. 16th century is the time. // Beginn: 1500. (1501 - 1) / 100 + 1 = 16. 16th century is the time.
$start_cen = (intval($timeInfo['zeit_beginn'])); $start_cen = (\intval($timeInfo['zeit_beginn']));
// End: 1600. 16th century is the time. // End: 1600. 16th century is the time.
$end_cen = (intval($timeInfo['zeit_ende'])); $end_cen = (\intval($timeInfo['zeit_ende']));
$suffixMode = self::getSuffixModeForYearsWSuffix((intval($timeInfo['zeit_beginn']) - 1), intval($timeInfo['zeit_ende'])); $suffixMode = self::getSuffixModeForYearsWSuffix((\intval($timeInfo['zeit_beginn']) - 1), \intval($timeInfo['zeit_ende']));
$output = []; $output = [];
if ($start_cen === $end_cen - 9) { if ($start_cen === $end_cen - 9) {
foreach (self::LANGS_DECADE_FORMAT as $tLang => $format) { foreach (self::LANGS_DECADE_FORMAT as $tLang => $format) {
$tLangValue = sprintf($format, (string)$start_cen, (string)$end_cen); $tLangValue = \sprintf($format, (string)$start_cen, (string)$end_cen);
if (!empty(self::LANGS_SYLLABLE_CLEANING[$tLang])) $tLangValue = strtr($tLangValue, self::LANGS_SYLLABLE_CLEANING[$tLang]); if (!empty(self::LANGS_SYLLABLE_CLEANING[$tLang])) $tLangValue = \strtr($tLangValue, self::LANGS_SYLLABLE_CLEANING[$tLang]);
$output[$tLang] = self::applyBcBceFormat($tLang, $tLangValue, $suffixMode); $output[$tLang] = self::applyBcBceFormat($tLang, $tLangValue, $suffixMode);
} }
} }
else { else {
foreach (self::LANGS_DECADES_FORMAT as $tLang => $format) { foreach (self::LANGS_DECADES_FORMAT as $tLang => $format) {
$tLangValue = sprintf($format, (string)$start_cen, (string)($end_cen - 9)); $tLangValue = \sprintf($format, (string)$start_cen, (string)($end_cen - 9));
if (!empty(self::LANGS_SYLLABLE_CLEANING[$tLang])) $tLangValue = strtr($tLangValue, self::LANGS_SYLLABLE_CLEANING[$tLang]); if (!empty(self::LANGS_SYLLABLE_CLEANING[$tLang])) $tLangValue = \strtr($tLangValue, self::LANGS_SYLLABLE_CLEANING[$tLang]);
$output[$tLang] = self::applyBcBceFormat($tLang, $tLangValue, $suffixMode); $output[$tLang] = self::applyBcBceFormat($tLang, $tLangValue, $suffixMode);
} }
} }
@ -634,8 +634,8 @@ final class NodaTimeAutotranslater {
*/ */
public static function translateYearsAfterStart(array $timeInfo):array { public static function translateYearsAfterStart(array $timeInfo):array {
if (empty(trim((string)$timeInfo['zeit_zaehlzeit_monat'], " ,.;0"))) { if (empty(\trim((string)$timeInfo['zeit_zaehlzeit_monat'], " ,.;0"))) {
$timeInfo['zeit_beginn'] = strval(intval($timeInfo['zeit_beginn']) - 1); $timeInfo['zeit_beginn'] = \strval(\intval($timeInfo['zeit_beginn']) - 1);
} }
# else throw new Exception("Unhandled split case. Counting time is: " . var_export($timeInfo, true)); # else throw new Exception("Unhandled split case. Counting time is: " . var_export($timeInfo, true));
$innerTimeInfo = $timeInfo; $innerTimeInfo = $timeInfo;
@ -646,7 +646,7 @@ final class NodaTimeAutotranslater {
$dateAlone = self::getTranslations($innerTimeInfo)[$tLang]; $dateAlone = self::getTranslations($innerTimeInfo)[$tLang];
$timeName = sprintf($format, $dateAlone); $timeName = \sprintf($format, $dateAlone);
$output[$tLang] = $timeName; $output[$tLang] = $timeName;
} }
@ -663,7 +663,7 @@ final class NodaTimeAutotranslater {
*/ */
public static function translateYearsSinceStart(array $timeInfo):array { public static function translateYearsSinceStart(array $timeInfo):array {
$start = intval($timeInfo['zeit_beginn']); $start = \intval($timeInfo['zeit_beginn']);
if (substr((string)$timeInfo['zeit_name'], 0, 5) === "Nach ") { if (substr((string)$timeInfo['zeit_name'], 0, 5) === "Nach ") {
return self::translateYearsAfterStart($timeInfo); return self::translateYearsAfterStart($timeInfo);
@ -677,7 +677,7 @@ final class NodaTimeAutotranslater {
$dateAlone = self::getTranslations($innerTimeInfo)[$tLang]; $dateAlone = self::getTranslations($innerTimeInfo)[$tLang];
$timeName = sprintf($format, $dateAlone); $timeName = \sprintf($format, $dateAlone);
$output[$tLang] = $timeName; $output[$tLang] = $timeName;
} }
@ -694,10 +694,10 @@ final class NodaTimeAutotranslater {
*/ */
public static function translateYearsBeforeEnd(array $timeInfo):array { public static function translateYearsBeforeEnd(array $timeInfo):array {
if (empty(trim((string)$timeInfo['zeit_zaehlzeit_monat'], " ,.;0"))) { if (empty(\trim((string)$timeInfo['zeit_zaehlzeit_monat'], " ,.;0"))) {
$timeInfo['zeit_ende'] = strval(intval($timeInfo['zeit_ende']) + 1); $timeInfo['zeit_ende'] = \strval(\intval($timeInfo['zeit_ende']) + 1);
} }
$end = intval($timeInfo['zeit_ende']); $end = \intval($timeInfo['zeit_ende']);
$innerTimeInfo = $timeInfo; $innerTimeInfo = $timeInfo;
$innerTimeInfo['zeit_beginn'] = $timeInfo['zeit_ende']; $innerTimeInfo['zeit_beginn'] = $timeInfo['zeit_ende'];
@ -707,7 +707,7 @@ final class NodaTimeAutotranslater {
$dateAlone = self::getTranslations($innerTimeInfo)[$tLang]; $dateAlone = self::getTranslations($innerTimeInfo)[$tLang];
$timeName = sprintf($format, $dateAlone); $timeName = \sprintf($format, $dateAlone);
$output[$tLang] = $timeName; $output[$tLang] = $timeName;
} }
return $output; return $output;
@ -723,7 +723,7 @@ final class NodaTimeAutotranslater {
*/ */
public static function translateYearsUntilEnd(array $timeInfo):array { public static function translateYearsUntilEnd(array $timeInfo):array {
$end = intval($timeInfo['zeit_ende']); $end = \intval($timeInfo['zeit_ende']);
if (substr((string)$timeInfo['zeit_name'], 0, 4) === "Vor ") { if (substr((string)$timeInfo['zeit_name'], 0, 4) === "Vor ") {
return self::translateYearsBeforeEnd($timeInfo); return self::translateYearsBeforeEnd($timeInfo);
@ -737,7 +737,7 @@ final class NodaTimeAutotranslater {
$dateAlone = self::getTranslations($innerTimeInfo)[$tLang]; $dateAlone = self::getTranslations($innerTimeInfo)[$tLang];
$timeName = sprintf($format, $dateAlone); $timeName = \sprintf($format, $dateAlone);
$output[$tLang] = $timeName; $output[$tLang] = $timeName;
} }
return $output; return $output;
@ -785,9 +785,9 @@ final class NodaTimeAutotranslater {
return self::translateYearsWithSuffix($timeInfo); return self::translateYearsWithSuffix($timeInfo);
} }
$suffixMode = self::getSuffixModeForYearsWSuffix((intval($timeInfo['zeit_beginn']) - 1), intval($timeInfo['zeit_ende'])); $suffixMode = self::getSuffixModeForYearsWSuffix((\intval($timeInfo['zeit_beginn']) - 1), \intval($timeInfo['zeit_ende']));
if (trim((string)$timeInfo['zeit_zaehlzeit_tag'], ", .0") === "") { if (\trim((string)$timeInfo['zeit_zaehlzeit_tag'], ", .0") === "") {
$dateStr = "{$timeInfo['zeit_zaehlzeit_jahr']}-{$timeInfo['zeit_zaehlzeit_monat']}-05 00:00:01"; $dateStr = "{$timeInfo['zeit_zaehlzeit_jahr']}-{$timeInfo['zeit_zaehlzeit_monat']}-05 00:00:01";
$usecase = self::USECASE_MONTH; $usecase = self::USECASE_MONTH;
} }
@ -796,16 +796,16 @@ final class NodaTimeAutotranslater {
$usecase = self::USECASE_DAY; $usecase = self::USECASE_DAY;
} }
$dateGeneral = strtotime($dateStr); $dateGeneral = \strtotime($dateStr);
$output = []; $output = [];
foreach (self::LANGS_TO_LOCALES as $tLang => $locale) { foreach (self::LANGS_TO_LOCALES as $tLang => $locale) {
setlocale(LC_TIME, $locale); \setlocale(LC_TIME, $locale);
if ($locale !== setlocale(LC_TIME, "0")) continue; if ($locale !== \setlocale(LC_TIME, "0")) continue;
if ($usecase === self::USECASE_MONTH) $tLangValue = strftime(getMonthFormatByLang($tLang), $dateGeneral ?: 0); if ($usecase === self::USECASE_MONTH) $tLangValue = \strftime(getMonthFormatByLang($tLang), $dateGeneral ?: 0);
else { # if ($usecase === self::USECASE_DAY) else { # if ($usecase === self::USECASE_DAY)
$tLangValue = strftime(getDateFormatByLang($tLang), $dateGeneral ?: 0); $tLangValue = \strftime(getDateFormatByLang($tLang), $dateGeneral ?: 0);
} }
$output[$tLang] = self::applyBcBceFormat($tLang, $tLangValue, $suffixMode); $output[$tLang] = self::applyBcBceFormat($tLang, $tLangValue, $suffixMode);

View File

@ -123,15 +123,15 @@ final class NodaTimeSplitter {
*/ */
private static function clean_input(string $input):string { private static function clean_input(string $input):string {
while (strpos($input, " -") !== false) $input = str_replace(" -", "-", $input); while (\strpos($input, " -") !== false) $input = \str_replace(" -", "-", $input);
while (strpos($input, "- ") !== false) $input = str_replace("- ", "-", $input); while (\strpos($input, "- ") !== false) $input = \str_replace("- ", "-", $input);
$input = strtr($input, self::STRINGS_TO_CLEAN); $input = \strtr($input, self::STRINGS_TO_CLEAN);
foreach (self::STRINGS_TO_CLEAN_START as $toCleanFrom => $toCleanTo) { foreach (self::STRINGS_TO_CLEAN_START as $toCleanFrom => $toCleanTo) {
if (strpos($input, $toCleanFrom) === 0) { if (strpos($input, $toCleanFrom) === 0) {
$input = str_replace($toCleanFrom, $toCleanTo, $input); $input = \str_replace($toCleanFrom, $toCleanTo, $input);
} }
} }
while (strpos($input, "..") !== false) $input = str_replace("..", ".", $input); while (strpos($input, "..") !== false) $input = \str_replace("..", ".", $input);
return trim($input, ", [](){}"); return trim($input, ", [](){}");
@ -146,9 +146,9 @@ final class NodaTimeSplitter {
*/ */
private static function is_numeric(string $input):bool { private static function is_numeric(string $input):bool {
if (is_numeric($input) if (\is_numeric($input)
and strpos($input, " ") === false and \strpos($input, " ") === false
and strpos($input, ".") === false and \strpos($input, ".") === false
) { ) {
return true; return true;
} }
@ -169,12 +169,12 @@ final class NodaTimeSplitter {
private static function validateDateSubstr(string $datum, int $start, int $end = 10000):string { private static function validateDateSubstr(string $datum, int $start, int $end = 10000):string {
if ($start !== 0 if ($start !== 0
&& !in_array(substr($datum, $start - 1, 1), ["-", " ", "."], true) && !\in_array(\substr($datum, $start - 1, 1), ["-", " ", "."], true)
) { ) {
return ""; return "";
} }
$output = substr($datum, $start, $end); $output = \substr($datum, $start, $end);
if (self::is_numeric($output)) return $output; if (self::is_numeric($output)) return $output;
return ""; return "";
@ -190,12 +190,12 @@ final class NodaTimeSplitter {
public static function timePartsToTimeName(array $moda):string { public static function timePartsToTimeName(array $moda):string {
if (!empty($moda[5]) and $moda[5] === "Vor" and $moda[0] === "?") { if (!empty($moda[5]) and $moda[5] === "Vor" and $moda[0] === "?") {
if (empty(trim($moda[2], "0 "))) $moda[1] = strval(intval($moda[1]) + 1); if (empty(trim($moda[2], "0 "))) $moda[1] = \strval(\intval($moda[1]) + 1);
$moda[0] = $moda[1]; $moda[0] = $moda[1];
$prefix = "Vor "; $prefix = "Vor ";
} }
else if (!empty($moda[5]) and $moda[5] === "Nach" and $moda[1] === "?") { else if (!empty($moda[5]) and $moda[5] === "Nach" and $moda[1] === "?") {
if (empty(trim($moda[2], "0 "))) $moda[0] = strval(intval($moda[0]) - 1); if (empty(trim($moda[2], "0 "))) $moda[0] = \strval(\intval($moda[0]) - 1);
$moda[1] = $moda[0]; $moda[1] = $moda[0];
$prefix = "Nach "; $prefix = "Nach ";
} }
@ -209,8 +209,8 @@ final class NodaTimeSplitter {
} }
else $prefix = ""; else $prefix = "";
$moda[0] = intval($moda[0]); $moda[0] = \intval($moda[0]);
$moda[1] = intval($moda[1]); $moda[1] = \intval($moda[1]);
if ($moda[0] < 0 && $moda[1] < 0) { if ($moda[0] < 0 && $moda[1] < 0) {
$suffix = " v. Chr."; $suffix = " v. Chr.";
@ -220,13 +220,13 @@ final class NodaTimeSplitter {
} }
else $suffix = ""; else $suffix = "";
$moda[0] = abs($moda[0]); $moda[0] = \abs($moda[0]);
$moda[1] = abs($moda[1]); $moda[1] = \abs($moda[1]);
if ($moda[0] !== $moda[1]) { if ($moda[0] !== $moda[1]) {
return "{$prefix}{$moda[0]}-{$moda[1]}{$suffix}"; return "{$prefix}{$moda[0]}-{$moda[1]}{$suffix}";
} }
else if (intval($moda[2]) !== 0 and intval($moda[3]) !== 0) { else if (\intval($moda[2]) !== 0 and \intval($moda[3]) !== 0) {
return "{$prefix}{$moda[3]}.{$moda[2]}.{$moda[0]}{$suffix}"; return "{$prefix}{$moda[3]}.{$moda[2]}.{$moda[0]}{$suffix}";
} }
else if ($moda[0] === $moda[1] && trim((string)$moda[2], " 0") === "" && trim((string)$moda[3], " 0") === "") { else if ($moda[0] === $moda[1] && trim((string)$moda[2], " 0") === "" && trim((string)$moda[3], " 0") === "") {
@ -252,19 +252,19 @@ final class NodaTimeSplitter {
if ($moda[0] === "?") { if ($moda[0] === "?") {
if (!empty($moda[5]) and $moda[5] === "Vor" and empty(trim($moda[2], " 0"))) { if (!empty($moda[5]) and $moda[5] === "Vor" and empty(trim($moda[2], " 0"))) {
return abs(intval($moda[1])) + 1; return \abs(\intval($moda[1])) + 1;
} }
return abs(intval($moda[1])); return \abs(\intval($moda[1]));
} }
if ($moda[1] === "?") { if ($moda[1] === "?") {
if (!empty($moda[5]) and $moda[5] === "Nach" and empty(trim($moda[2], " 0"))) { if (!empty($moda[5]) and $moda[5] === "Nach" and empty(trim($moda[2], " 0"))) {
return abs(intval($moda[0])) - 1; return \abs(\intval($moda[0])) - 1;
} }
return abs(intval($moda[0])); return \abs(\intval($moda[0]));
} }
return abs((int)ceil(intval($moda[1]) - ((intval($moda[1]) - intval($moda[0])) / 2))); return \abs((int)\ceil(\intval($moda[1]) - ((\intval($moda[1]) - \intval($moda[0])) / 2)));
} }
@ -335,7 +335,7 @@ final class NodaTimeSplitter {
*/ */
public static function pad_to_four(string $input):string { public static function pad_to_four(string $input):string {
return substr("0000" . $input, -4); return \substr("0000" . $input, -4);
} }
@ -348,7 +348,7 @@ final class NodaTimeSplitter {
*/ */
public static function pad_to_two(string $input):string { public static function pad_to_two(string $input):string {
return substr("00" . $input, -2); return \substr("00" . $input, -2);
} }
@ -363,11 +363,11 @@ final class NodaTimeSplitter {
$datum = self::clean_input($datum); $datum = self::clean_input($datum);
if (preg_match("/\ v\.\ Chr\.$/", $datum)) { if (\preg_match("/\ v\.\ Chr\.$/", $datum)) {
if ($output = self::attempt_splitting(substr($datum, 0, -8))) { if ($output = self::attempt_splitting(\substr($datum, 0, -8))) {
$start = strval(-1 * intval($output[1])); $start = \strval(-1 * \intval($output[1]));
$end = strval(-1 * intval($output[0])); $end = \strval(-1 * \intval($output[0]));
if (intval($start) > intval($end)) { if (\intval($start) > \intval($end)) {
$startToSet = $end; $startToSet = $end;
$end = $start; $end = $start;
$start = $startToSet; $start = $startToSet;
@ -376,7 +376,7 @@ final class NodaTimeSplitter {
} }
} }
$datum = str_replace(". ", ".", $datum); $datum = \str_replace(". ", ".", $datum);
if (self::stri_occurs($datum, self::STOP_STRINGS_GERMAN)) { if (self::stri_occurs($datum, self::STOP_STRINGS_GERMAN)) {
return []; return [];
@ -393,12 +393,12 @@ final class NodaTimeSplitter {
} }
} }
if (empty($monat) and self::is_numeric((string)substr($datum, 3, 2))) $monat = substr($datum, 3, 2); if (empty($monat) and self::is_numeric((string)\substr($datum, 3, 2))) $monat = \substr($datum, 3, 2);
if (self::is_numeric((string)substr($datum, 0, 2))) $day = substr($datum, 0, 2); if (self::is_numeric((string)\substr($datum, 0, 2))) $day = \substr($datum, 0, 2);
else if (substr($datum, 1, 1) === "." and self::is_numeric((string)substr($datum, 0, 1))) $day = "0" . substr($datum, 0, 1); else if (\substr($datum, 1, 1) === "." and self::is_numeric((string)\substr($datum, 0, 1))) $day = "0" . \substr($datum, 0, 1);
if (self::is_numeric((string)substr($datum, -4))) $year = substr($datum, -4); if (self::is_numeric((string)\substr($datum, -4))) $year = \substr($datum, -4);
if (!empty($year) and !empty($monat) and !empty($day) and $use_day) { if (!empty($year) and !empty($monat) and !empty($day) and $use_day) {
return [$year, $year, $monat, $day, '+', ""]; return [$year, $year, $monat, $day, '+', ""];
@ -421,11 +421,11 @@ final class NodaTimeSplitter {
$datum = self::clean_input($datum); $datum = self::clean_input($datum);
if (preg_match("/^Kr\.\ e\.\ /", $datum)) { if (\preg_match("/^Kr\.\ e\.\ /", $datum)) {
if ($output = self::attempt_splitting(substr($datum, 7))) { if ($output = self::attempt_splitting(\substr($datum, 7))) {
$start = strval(-1 * intval($output[1])); $start = \strval(-1 * \intval($output[1]));
$end = strval(-1 * intval($output[0])); $end = \strval(-1 * \intval($output[0]));
if (intval($start) > intval($end)) { if (\intval($start) > \intval($end)) {
$startToSet = $end; $startToSet = $end;
$end = $start; $end = $start;
$start = $startToSet; $start = $startToSet;
@ -434,9 +434,9 @@ final class NodaTimeSplitter {
} }
} }
if (preg_match("/^[0-9][0-9][0-9][0-9]\-t(ő|ó)l(\ |\-)[0-9][0-9][0-9][0-9]\-ig$/", $datum)) { 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); $start = \substr($datum, 0, 4);
$end = substr($datum, -7, 4); $end = \substr($datum, -7, 4);
return [$start, $end, "00", "00", "+", ""]; return [$start, $end, "00", "00", "+", ""];
} }
@ -453,8 +453,8 @@ final class NodaTimeSplitter {
} }
} }
if (empty($monat) and self::is_numeric((string)substr($datum, 5, 2))) $monat = substr($datum, 5, 2); if (empty($monat) and self::is_numeric((string)\substr($datum, 5, 2))) $monat = \substr($datum, 5, 2);
else if (empty($monat) and self::is_numeric((string)substr($datum, 6, 2))) $monat = substr($datum, 6, 2); else if (empty($monat) and self::is_numeric((string)\substr($datum, 6, 2))) $monat = \substr($datum, 6, 2);
$day = self::validateDateSubstr($datum, -2); $day = self::validateDateSubstr($datum, -2);
if (empty($day)) $day = self::validateDateSubstr($datum, -3, 2); if (empty($day)) $day = self::validateDateSubstr($datum, -3, 2);
@ -462,14 +462,14 @@ final class NodaTimeSplitter {
if (empty($day)) $day = self::validateDateSubstr($datum, -5, 2); if (empty($day)) $day = self::validateDateSubstr($datum, -5, 2);
if (empty($day)) $day = self::validateDateSubstr($datum, -6, 2); if (empty($day)) $day = self::validateDateSubstr($datum, -6, 2);
if (substr($datum, -2, 1) === " " and self::is_numeric((string)substr($datum, -1, 1))) { if (\substr($datum, -2, 1) === " " and self::is_numeric((string)\substr($datum, -1, 1))) {
$day = "0" . substr($datum, -1, 1); $day = "0" . \substr($datum, -1, 1);
} }
else if ((empty($day)) and substr($datum, -3, 1) === " " and self::is_numeric((string)substr($datum, -2, 1))) { else if ((empty($day)) and \substr($datum, -3, 1) === " " and self::is_numeric((string)\substr($datum, -2, 1))) {
$day = "0" . substr($datum, -2, 1); $day = "0" . \substr($datum, -2, 1);
} }
if (self::is_numeric((string)substr($datum, 0, 4))) $year = substr($datum, 0, 4); if (self::is_numeric((string)\substr($datum, 0, 4))) $year = \substr($datum, 0, 4);
if (!empty($year) and !empty($monat) and !empty($day)) { if (!empty($year) and !empty($monat) and !empty($day)) {
return [$year, $year, $monat, $day, '+', ""]; return [$year, $year, $monat, $day, '+', ""];
@ -492,11 +492,11 @@ final class NodaTimeSplitter {
$datum = self::clean_input($datum); $datum = self::clean_input($datum);
if (!($timeInt = strtotime($datum))) { if (!($timeInt = \strtotime($datum))) {
return []; return [];
} }
return [date("Y", $timeInt), date("m", $timeInt), date("d", $timeInt), '+', ""]; return [\date("Y", $timeInt), \date("m", $timeInt), \date("d", $timeInt), '+', ""];
} }
@ -512,64 +512,64 @@ final class NodaTimeSplitter {
$datum = self::clean_input($datum); $datum = self::clean_input($datum);
// 10000-20000 // 10000-20000
if (!empty(preg_match("/^[0-9]{5}(\-|\/)[0-9]{5}$/", $datum))) { if (!empty(\preg_match("/^[0-9]{5}(\-|\/)[0-9]{5}$/", $datum))) {
$start = substr($datum, 0, 5); $start = \substr($datum, 0, 5);
$end = substr($datum, 6, 5); $end = \substr($datum, 6, 5);
return [$start, $end, "00", "00", "+", ""]; return [$start, $end, "00", "00", "+", ""];
} }
// 0000-0000 // 0000-0000
if (preg_match("/^[0-9]{4}(\-|\/)[0-9]{4}(\.|)$/", $datum)) { if (\preg_match("/^[0-9]{4}(\-|\/)[0-9]{4}(\.|)$/", $datum)) {
$start = substr($datum, 0, 4); $start = \substr($datum, 0, 4);
$end = substr($datum, 5, 4); $end = \substr($datum, 5, 4);
return [$start, $end, "00", "00", "+", ""]; return [$start, $end, "00", "00", "+", ""];
} }
if (preg_match("/^[0-9]\.[0-9][0-9][0-9](\-|\/)[0-9]\.[0-9][0-9][0-9]$/", $datum)) { if (\preg_match("/^[0-9]\.[0-9][0-9][0-9](\-|\/)[0-9]\.[0-9][0-9][0-9]$/", $datum)) {
$datum = str_replace(".", "", $datum); $datum = \str_replace(".", "", $datum);
$start = substr($datum, 0, 4); $start = \substr($datum, 0, 4);
$end = substr($datum, 5, 4); $end = \substr($datum, 5, 4);
return [$start, $end, "00", "00", "+", ""]; return [$start, $end, "00", "00", "+", ""];
} }
// German TT.MM.JJJJ / TT.MM.JJJ / TT.MM.JJ / TT.MM.J // German TT.MM.JJJJ / TT.MM.JJJ / TT.MM.JJ / TT.MM.J
if (preg_match("/^[0-9][0-9]\.[0-9][0-9]\.([0-9][0-9][0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9]|[0-9])$/", $datum)) { // German T.MM.JJJJ if (\preg_match("/^[0-9][0-9]\.[0-9][0-9]\.([0-9][0-9][0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9]|[0-9])$/", $datum)) { // German T.MM.JJJJ
$start = substr($datum, 6, 4); $start = \substr($datum, 6, 4);
$month = substr($datum, 3, 2); $month = \substr($datum, 3, 2);
$day = substr($datum, 0, 2); $day = \substr($datum, 0, 2);
return [$start, $start, $month, $day, "+", ""]; return [$start, $start, $month, $day, "+", ""];
} }
// German TT.M.JJJJ / TT.M.JJJ / TT.M.JJ / TT.M.J // German TT.M.JJJJ / TT.M.JJJ / TT.M.JJ / TT.M.J
if (preg_match("/^[0-9][0-9]\.[0-9]\.([0-9][0-9][0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9]|[0-9])$/", $datum)) { // German T.MM.JJJJ if (\preg_match("/^[0-9][0-9]\.[0-9]\.([0-9][0-9][0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9]|[0-9])$/", $datum)) { // German T.MM.JJJJ
$start = substr($datum, 5, 4); $start = \substr($datum, 5, 4);
$month = "0" . substr($datum, 3, 1); $month = "0" . \substr($datum, 3, 1);
$day = substr($datum, 0, 2); $day = \substr($datum, 0, 2);
return [$start, $start, $month, $day, "+", ""]; return [$start, $start, $month, $day, "+", ""];
} }
// German T.MM.JJJJ / T.MM.JJJ / T.MM.JJ / T.MM.J // German T.MM.JJJJ / T.MM.JJJ / T.MM.JJ / T.MM.J
if (preg_match("/^[0-9]\.[0-9][0-9]\.([0-9][0-9][0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9]|[0-9])$/", $datum)) { if (\preg_match("/^[0-9]\.[0-9][0-9]\.([0-9][0-9][0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9]|[0-9])$/", $datum)) {
$start = substr($datum, 5, 4); $start = \substr($datum, 5, 4);
$month = substr($datum, 2, 2); $month = \substr($datum, 2, 2);
$day = "0" . substr($datum, 0, 1); $day = "0" . \substr($datum, 0, 1);
return [$start, $start, $month, $day, "+", ""]; return [$start, $start, $month, $day, "+", ""];
} }
// German T.M.JJJJ / T.M.JJJ / T.M.JJ / T.M.J // German T.M.JJJJ / T.M.JJJ / T.M.JJ / T.M.J
if (preg_match("/^[0-9]\.[0-9]\.([0-9][0-9][0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9]|[0-9])$/", $datum)) { if (\preg_match("/^[0-9]\.[0-9]\.([0-9][0-9][0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9]|[0-9])$/", $datum)) {
$start = substr($datum, 4, 4); $start = \substr($datum, 4, 4);
$month = "0" . substr($datum, 2, 1); $month = "0" . \substr($datum, 2, 1);
$day = "0" . substr($datum, 0, 1); $day = "0" . \substr($datum, 0, 1);
return [$start, $start, $month, $day, "+", ""]; return [$start, $start, $month, $day, "+", ""];
} }
// Intl': 2020-12-20 // Intl': 2020-12-20
if (preg_match("/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$/", $datum)) { // German Y-m if (\preg_match("/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$/", $datum)) { // German Y-m
$start = substr($datum, 0, 4); $start = \substr($datum, 0, 4);
$month = substr($datum, 5, 2); $month = \substr($datum, 5, 2);
if (intval($month) < 13) { if (\intval($month) < 13) {
$day = substr($datum, 8, 2); $day = \substr($datum, 8, 2);
return [$start, $start, $month, $day, "+", ""]; return [$start, $start, $month, $day, "+", ""];
} }
else { else {
@ -577,10 +577,10 @@ final class NodaTimeSplitter {
} }
} }
// Intl': 2020-12 // Intl': 2020-12
if (preg_match("/^[0-9]{4}\-[0-9]{2}$/", $datum)) { // German Y-m if (\preg_match("/^[0-9]{4}\-[0-9]{2}$/", $datum)) { // German Y-m
$start = substr($datum, 0, 4); $start = \substr($datum, 0, 4);
$month = substr($datum, 5, 2); $month = \substr($datum, 5, 2);
if (intval($month) < 13) { if (\intval($month) < 13) {
return [$start, $start, $month, "00", "+", ""]; return [$start, $start, $month, "00", "+", ""];
} }
else { else {
@ -589,84 +589,84 @@ final class NodaTimeSplitter {
} }
// German MM.JJJJ // German MM.JJJJ
if (preg_match("/^[0-9]{2}\.[0-9]{4}$/", $datum)) { // German Y-m if (\preg_match("/^[0-9]{2}\.[0-9]{4}$/", $datum)) { // German Y-m
$start = substr($datum, 3, 4); $start = \substr($datum, 3, 4);
$month = substr($datum, 0, 2); $month = \substr($datum, 0, 2);
return [$start, $start, $month, "00", "+", ""]; return [$start, $start, $month, "00", "+", ""];
} }
if (preg_match("/^[0-9]\.[0-9]{4}$/", $datum)) { // German Y-m if (\preg_match("/^[0-9]\.[0-9]{4}$/", $datum)) { // German Y-m
$start = substr($datum, 2, 4); $start = \substr($datum, 2, 4);
$month = "0" . substr($datum, 0, 1); $month = "0" . \substr($datum, 0, 1);
return [$start, $start, $month, "00", "+", ""]; return [$start, $start, $month, "00", "+", ""];
} }
if (preg_match("/^[0-9]{4}\.[0-9]{2}\.[0-9]{1,2}(\.|)$/", $datum)) { // Hungarian Y-m-d if (\preg_match("/^[0-9]{4}\.[0-9]{2}\.[0-9]{1,2}(\.|)$/", $datum)) { // Hungarian Y-m-d
$start = substr($datum, 0, 4); $start = \substr($datum, 0, 4);
$month = substr($datum, 5, 2); $month = \substr($datum, 5, 2);
$day = self::pad_to_two(substr($datum, 8, 2)); $day = self::pad_to_two(\substr($datum, 8, 2));
if (intval($month) < 13) return [$start, $start, $month, $day, "+", ""]; if (\intval($month) < 13) return [$start, $start, $month, $day, "+", ""];
} }
if (preg_match("/^[0-9]{4}\.[0-9]{2}(\.|)$/", $datum)) { // Hungarian Y-m if (\preg_match("/^[0-9]{4}\.[0-9]{2}(\.|)$/", $datum)) { // Hungarian Y-m
$start = substr($datum, 0, 4); $start = \substr($datum, 0, 4);
$month = substr($datum, 5, 2); $month = \substr($datum, 5, 2);
if (intval($month) < 13) return [$start, $start, $month, "00", "+", ""]; if (\intval($month) < 13) return [$start, $start, $month, "00", "+", ""];
} }
if (preg_match("/^[0-9]{4}\-[0-9]{2}$/", $datum)) { // Time spans: 1945-46 if (\preg_match("/^[0-9]{4}\-[0-9]{2}$/", $datum)) { // Time spans: 1945-46
$start = substr($datum, 0, 4); $start = \substr($datum, 0, 4);
$endDigits = substr($datum, 5, 2); $endDigits = \substr($datum, 5, 2);
if (intval($endDigits) > 12) return [$start, substr($datum, 0, 2) . $endDigits, "00", "00", "+", ""]; if (\intval($endDigits) > 12) return [$start, \substr($datum, 0, 2) . $endDigits, "00", "00", "+", ""];
} }
// 01.01.1920-31.12.1930 // 01.01.1920-31.12.1930
if (preg_match("/^01\.01\.[0-9]{4}\-31\.12\.[0-9]{4}$/", $datum)) { // Hungarian Y-m if (\preg_match("/^01\.01\.[0-9]{4}\-31\.12\.[0-9]{4}$/", $datum)) { // Hungarian Y-m
$start = substr($datum, 6, 4); $start = \substr($datum, 6, 4);
$end = substr($datum, -4); $end = \substr($datum, -4);
return [$start, $end, "00", "00", "+", ""]; return [$start, $end, "00", "00", "+", ""];
} }
// 303-305 (n. Chr.) // 303-305 (n. Chr.)
if (preg_match("/^[0-9]{3}\-[0-9]{3}$/", $datum)) { // Hungarian Y-m if (\preg_match("/^[0-9]{3}\-[0-9]{3}$/", $datum)) { // Hungarian Y-m
$start = substr($datum, 0, 3); $start = \substr($datum, 0, 3);
$end = substr($datum, -3); $end = \substr($datum, -3);
return ["0" . $start, "0" . $end, "00", "00", "+", ""]; return ["0" . $start, "0" . $end, "00", "00", "+", ""];
} }
// 1720-120 // 1720-120
if (preg_match("/^[0-9]{4}\-[0-9]{3}$/", $datum)) { // Hungarian Y-m if (\preg_match("/^[0-9]{4}\-[0-9]{3}$/", $datum)) { // Hungarian Y-m
$start = substr($datum, 0, 4); $start = \substr($datum, 0, 4);
$end = substr($datum, -3); $end = \substr($datum, -3);
return ["0" . $start, "0" . $end, "00", "00", "+", ""]; return ["0" . $start, "0" . $end, "00", "00", "+", ""];
} }
// 20-30 (n. Chr.) // 20-30 (n. Chr.)
if (preg_match("/^[0-9]{2}\-[0-9]{2}$/", $datum)) { // 20-40 (n. Chr.) if (\preg_match("/^[0-9]{2}\-[0-9]{2}$/", $datum)) { // 20-40 (n. Chr.)
$start = substr($datum, 0, 2); $start = \substr($datum, 0, 2);
$end = substr($datum, -2); $end = \substr($datum, -2);
return ["00" . $start, "00" . $end, "00", "00", "+", ""]; return ["00" . $start, "00" . $end, "00", "00", "+", ""];
} }
// 1920 // 1920
if (preg_match("/^[0-9]{4}(\.|)$/", $datum)) { if (\preg_match("/^[0-9]{4}(\.|)$/", $datum)) {
$start = substr($datum, 0, 4); $start = \substr($datum, 0, 4);
return [$start, $start, "00", "00", "+", ""]; return [$start, $start, "00", "00", "+", ""];
} }
// 1920 // 1920
if (preg_match("/^[0-9]{3}$/", $datum)) { if (\preg_match("/^[0-9]{3}$/", $datum)) {
$start = "0" . substr($datum, 0, 3); $start = "0" . \substr($datum, 0, 3);
return [$start, $start, "00", "00", "+", ""]; return [$start, $start, "00", "00", "+", ""];
} }
if (preg_match("/^[0-9]{2}$/", $datum)) { if (\preg_match("/^[0-9]{2}$/", $datum)) {
$start = "00" . substr($datum, 0, 2); $start = "00" . \substr($datum, 0, 2);
return [$start, $start, "00", "00", "+", ""]; return [$start, $start, "00", "00", "+", ""];
} }
// Special case for SMB: YYYY, MM. DD and YYYY, MM. // Special case for SMB: YYYY, MM. DD and YYYY, MM.
if (preg_match("/^[0-9]{4}\,\ [0-9]{2}\.(|\ [0-9]{2})$/", $datum)) { if (\preg_match("/^[0-9]{4}\,\ [0-9]{2}\.(|\ [0-9]{2})$/", $datum)) {
$start = substr($datum, 0, 4); $start = \substr($datum, 0, 4);
$month = substr($datum, 6, 2); $month = \substr($datum, 6, 2);
$day = self::pad_to_two(substr($datum, 10, 2)); $day = self::pad_to_two(\substr($datum, 10, 2));
return [$start, $start, $month, $day, "+", ""]; return [$start, $start, $month, $day, "+", ""];
} }
@ -685,146 +685,146 @@ final class NodaTimeSplitter {
$datum = self::clean_input($datum); $datum = self::clean_input($datum);
if (preg_match("/^[0-9]{4}\.[0-9]{2}\.[0-9]{2}(\.|)\-$/", $datum)) { // Hungarian Y-m if (\preg_match("/^[0-9]{4}\.[0-9]{2}\.[0-9]{2}(\.|)\-$/", $datum)) { // Hungarian Y-m
$start = substr($datum, 0, 4); $start = \substr($datum, 0, 4);
$month = substr($datum, 5, 2); $month = \substr($datum, 5, 2);
$day = substr($datum, 8, 2); $day = \substr($datum, 8, 2);
return [$start, "?", $month, $day, "+", ""]; return [$start, "?", $month, $day, "+", ""];
} }
if (preg_match("/^[0-9]{4}\.[0-9]{2}(\.|)\-$/", $datum)) { // Hungarian Y-m if (\preg_match("/^[0-9]{4}\.[0-9]{2}(\.|)\-$/", $datum)) { // Hungarian Y-m
$start = substr($datum, 0, 4); $start = \substr($datum, 0, 4);
$month = substr($datum, 5, 2); $month = \substr($datum, 5, 2);
return [$start, "?", $month, "00", "+", ""]; return [$start, "?", $month, "00", "+", ""];
} }
if (preg_match("/^[0-9]{4}\-$/", $datum)) { // Hungarian Y- if (\preg_match("/^[0-9]{4}\-$/", $datum)) { // Hungarian Y-
$start = substr($datum, 0, 4); $start = \substr($datum, 0, 4);
return [$start, "?", "00", "00", "+", ""]; return [$start, "?", "00", "00", "+", ""];
} }
if (preg_match("/^\-[0-9]{4}\.[0-9]{2}\.[0-9]{2}$/", $datum)) { // Hungarian Y-m if (\preg_match("/^\-[0-9]{4}\.[0-9]{2}\.[0-9]{2}$/", $datum)) { // Hungarian Y-m
$start = substr($datum, 1, 4); $start = \substr($datum, 1, 4);
$month = substr($datum, 6, 2); $month = \substr($datum, 6, 2);
$day = substr($datum, 9, 2); $day = \substr($datum, 9, 2);
return ["?", $start, $month, $day, "+", ""]; return ["?", $start, $month, $day, "+", ""];
} }
if (preg_match("/^\-[0-9]{4}\.[0-9]{2}$/", $datum)) { // Hungarian Y-m if (\preg_match("/^\-[0-9]{4}\.[0-9]{2}$/", $datum)) { // Hungarian Y-m
$start = substr($datum, 1, 4); $start = \substr($datum, 1, 4);
$month = substr($datum, 6, 2); $month = \substr($datum, 6, 2);
return ["?", $start, $month, "00", "+", ""]; return ["?", $start, $month, "00", "+", ""];
} }
if (preg_match("/^\-[0-9]{4}$/", $datum)) { // Hungarian -Y if (\preg_match("/^\-[0-9]{4}$/", $datum)) { // Hungarian -Y
$start = substr($datum, 1, 4); $start = \substr($datum, 1, 4);
return ["?", $start, "00", "00", "+", ""]; return ["?", $start, "00", "00", "+", ""];
} }
if (preg_match("/^(Nach|nach)\ /", $datum)) { if (\preg_match("/^(Nach|nach)\ /", $datum)) {
if (($spacePos = strpos($datum, " ")) === false) { if (($spacePos = \strpos($datum, " ")) === false) {
return []; return [];
} }
if ($output = self::attempt_splitting(substr($datum, $spacePos))) { if ($output = self::attempt_splitting(\substr($datum, $spacePos))) {
// Handle cases like "Nach 60er Jahre" with divergent start and end year // Handle cases like "Nach 60er Jahre" with divergent start and end year
if ($output[1] !== $output[0] and intval($output[1]) > intval($output[0])) { if ($output[1] !== $output[0] and \intval($output[1]) > \intval($output[0])) {
$output[0] = $output[1]; $output[0] = $output[1];
} }
$output[1] = "?"; $output[1] = "?";
if (empty(trim($output[2], "0 .,"))) $output[0] = strval((intval($output[0]) + 1)); if (empty(trim($output[2], "0 .,"))) $output[0] = \strval((\intval($output[0]) + 1));
$output[5] = "Nach"; $output[5] = "Nach";
return $output; return $output;
} }
} }
if (preg_match("/\ (\(nach|nach)$/", $datum)) { if (\preg_match("/\ (\(nach|nach)$/", $datum)) {
if (($spacePos = strpos($datum, " ")) === false) { if (($spacePos = \strpos($datum, " ")) === false) {
return []; return [];
} }
if ($output = self::attempt_splitting(substr($datum, 0, $spacePos))) { if ($output = self::attempt_splitting(\substr($datum, 0, $spacePos))) {
// Handle cases like "Nach 60er Jahre" with divergent start and end year // Handle cases like "Nach 60er Jahre" with divergent start and end year
if ($output[1] !== $output[0] and intval($output[1]) > intval($output[0])) { if ($output[1] !== $output[0] and \intval($output[1]) > \intval($output[0])) {
$output[0] = $output[1]; $output[0] = $output[1];
} }
$output[1] = "?"; $output[1] = "?";
if (empty(trim($output[2], "0 .,"))) $output[0] = strval((intval($output[0]) + 1)); if (empty(trim($output[2], "0 .,"))) $output[0] = \strval((\intval($output[0]) + 1));
$output[5] = "Nach"; $output[5] = "Nach";
return $output; return $output;
} }
} }
if (preg_match("/^(Vor|vor)\ /", $datum)) { if (\preg_match("/^(Vor|vor)\ /", $datum)) {
if (($spacePos = strpos($datum, " ")) === false) { if (($spacePos = \strpos($datum, " ")) === false) {
return []; return [];
} }
if ($output = self::attempt_splitting(substr($datum, $spacePos))) { if ($output = self::attempt_splitting(\substr($datum, $spacePos))) {
$output[0] = "?"; $output[0] = "?";
if (empty(trim($output[2], "0 .,"))) $output[1] = strval((intval($output[1]) - 1)); if (empty(trim($output[2], "0 .,"))) $output[1] = \strval((\intval($output[1]) - 1));
$output[5] = "Vor"; $output[5] = "Vor";
return $output; return $output;
} }
} }
if (preg_match("/\ (\(vor|\(Vor|vor)$/", $datum)) { if (\preg_match("/\ (\(vor|\(Vor|vor)$/", $datum)) {
if (($spacePos = strpos($datum, " ")) === false) { if (($spacePos = \strpos($datum, " ")) === false) {
return []; return [];
} }
if ($output = self::attempt_splitting(substr($datum, 0, $spacePos))) { if ($output = self::attempt_splitting(\substr($datum, 0, $spacePos))) {
$output[0] = "?"; $output[0] = "?";
if (empty(trim($output[2], "0 .,"))) $output[1] = strval((intval($output[1]) - 1)); if (empty(trim($output[2], "0 .,"))) $output[1] = \strval((\intval($output[1]) - 1));
$output[5] = "Vor"; $output[5] = "Vor";
return $output; return $output;
} }
} }
if (preg_match("/^(Ab|Seit|seit)\ /", $datum)) { if (\preg_match("/^(Ab|Seit|seit)\ /", $datum)) {
if (($spacePos = strpos($datum, " ")) === false) { if (($spacePos = \strpos($datum, " ")) === false) {
return []; return [];
} }
if ($output = self::attempt_splitting(substr($datum, $spacePos))) { if ($output = self::attempt_splitting(\substr($datum, $spacePos))) {
$output[1] = "?"; $output[1] = "?";
return $output; return $output;
} }
} }
// Endings beginning with a space // Endings beginning with a space
if (preg_match("/(\-től)$/", $datum)) { if (\preg_match("/(\-től)$/", $datum)) {
if (($spacePos = strrpos($datum, "-")) === false) { if (($spacePos = strrpos($datum, "-")) === false) {
return []; return [];
} }
if ($output = self::attempt_splitting(substr($datum, 0, $spacePos))) { if ($output = self::attempt_splitting(\substr($datum, 0, $spacePos))) {
$output[1] = "?"; $output[1] = "?";
return $output; return $output;
} }
} }
if (preg_match("/^(Bis|bis)\ /", $datum)) { if (\preg_match("/^(Bis|bis)\ /", $datum)) {
if (($spacePos = strpos($datum, " ")) === false) { if (($spacePos = \strpos($datum, " ")) === false) {
return []; return [];
} }
if ($output = self::attempt_splitting(substr($datum, $spacePos))) { if ($output = self::attempt_splitting(\substr($datum, $spacePos))) {
$output[0] = "?"; $output[0] = "?";
return $output; return $output;
} }
} }
// Endings beginning with a space // Endings beginning with a space
if (preg_match("/ (\(bis)$/", $datum)) { if (\preg_match("/ (\(bis)$/", $datum)) {
if (($spacePos = strrpos($datum, " ")) === false) { if (($spacePos = strrpos($datum, " ")) === false) {
return []; return [];
} }
if ($output = self::attempt_splitting(substr($datum, 0, $spacePos))) { if ($output = self::attempt_splitting(\substr($datum, 0, $spacePos))) {
$output[0] = "?"; $output[0] = "?";
return $output; return $output;
} }
} }
if (preg_match("/\-ig$/", $datum)) { if (\preg_match("/\-ig$/", $datum)) {
if (($spacePos = strrpos($datum, "-")) === false) { if (($spacePos = strrpos($datum, "-")) === false) {
return []; return [];
} }
if ($output = self::attempt_splitting(substr($datum, 0, $spacePos))) { if ($output = self::attempt_splitting(\substr($datum, 0, $spacePos))) {
$output[0] = "?"; $output[0] = "?";
return $output; return $output;
} }
@ -844,8 +844,8 @@ final class NodaTimeSplitter {
*/ */
public static function negotiate_century_span_bce_ce(string $start, string $end):array { public static function negotiate_century_span_bce_ce(string $start, string $end):array {
$start = intval($start); $start = \intval($start);
$end = intval($end); $end = \intval($end);
if ($start < $end) { if ($start < $end) {
return [(string)($start - 1) . "01", $end . "00", "00", "00", "+", ""]; return [(string)($start - 1) . "01", $end . "00", "00", "00", "+", ""];
@ -868,44 +868,44 @@ final class NodaTimeSplitter {
$bcBceIndicator = '+'; $bcBceIndicator = '+';
// 17. Jahrhundert // 17. Jahrhundert
if (preg_match("/^[0-9][0-9]\.\ (Jh\.|Jahrhundert|sz|század)$/", $datum)) { if (\preg_match("/^[0-9][0-9]\.\ (Jh\.|Jahrhundert|sz|század)$/", $datum)) {
if ($centuryNo = intval(substr($datum, 0, 2))) { if ($centuryNo = \intval(\substr($datum, 0, 2))) {
$centuryNo--; $centuryNo--;
return [(string)$centuryNo . "01", strval($centuryNo + 1) . "00", "00", "00", $bcBceIndicator, ""]; return [(string)$centuryNo . "01", \strval($centuryNo + 1) . "00", "00", "00", $bcBceIndicator, ""];
} }
} }
// 1. Jahrhundert // 1. Jahrhundert
if (preg_match("/^[0-9]\.\ (Jh\.|Jahrhundert|sz|század)$/", $datum)) { if (\preg_match("/^[0-9]\.\ (Jh\.|Jahrhundert|sz|század)$/", $datum)) {
if ($centuryNo = intval(substr($datum, 0, 1))) { if ($centuryNo = \intval(\substr($datum, 0, 1))) {
$centuryNo--; $centuryNo--;
return [(string)$centuryNo . "01", strval($centuryNo + 1) . "00", "00", "00", $bcBceIndicator, ""]; return [(string)$centuryNo . "01", \strval($centuryNo + 1) . "00", "00", "00", $bcBceIndicator, ""];
} }
} }
// 17.-18. Jahrhundert // 17.-18. Jahrhundert
if (preg_match("/^[0-9]{2}(\.|)(|\ Jh\.||\ Jahrhundert||\ sz||\ század)\-[0-9]{2}\.\ (Jh\.|Jahrhundert|sz|század)$/", $datum)) { if (\preg_match("/^[0-9]{2}(\.|)(|\ Jh\.||\ Jahrhundert||\ sz||\ század)\-[0-9]{2}\.\ (Jh\.|Jahrhundert|sz|század)$/", $datum)) {
if (($dashPos = strpos($datum, "-")) !== false) { if (($dashPos = \strpos($datum, "-")) !== false) {
return self::negotiate_century_span_bce_ce(substr($datum, 0, 2), substr($datum, $dashPos + 1, 2)); return self::negotiate_century_span_bce_ce(\substr($datum, 0, 2), \substr($datum, $dashPos + 1, 2));
} }
} }
// 1.-12. Jahrhundert // 1.-12. Jahrhundert
if (preg_match("/^[0-9](\.|)(|\ Jh\.||\ Jahrhundert||\ sz||\ század)\-[0-9]{2}\.\ (Jh\.|Jahrhundert|sz|század)$/", $datum)) { if (\preg_match("/^[0-9](\.|)(|\ Jh\.||\ Jahrhundert||\ sz||\ század)\-[0-9]{2}\.\ (Jh\.|Jahrhundert|sz|század)$/", $datum)) {
if (($dashPos = strpos($datum, "-")) !== false) { if (($dashPos = \strpos($datum, "-")) !== false) {
return self::negotiate_century_span_bce_ce(substr($datum, 0, 1), substr($datum, $dashPos + 1, 2)); return self::negotiate_century_span_bce_ce(\substr($datum, 0, 1), \substr($datum, $dashPos + 1, 2));
} }
} }
// 1.-2. Jahrhundert // 1.-2. Jahrhundert
if (preg_match("/^[0-9](\.|)(|\ Jh\.||\ Jahrhundert||\ sz||\ század)\-[0-9]\.\ (Jh\.|Jahrhundert|sz|század)$/", $datum)) { if (\preg_match("/^[0-9](\.|)(|\ Jh\.||\ Jahrhundert||\ sz||\ század)\-[0-9]\.\ (Jh\.|Jahrhundert|sz|század)$/", $datum)) {
if (($dashPos = strpos($datum, "-")) !== false) { if (($dashPos = \strpos($datum, "-")) !== false) {
return self::negotiate_century_span_bce_ce(substr($datum, 0, 1), substr($datum, $dashPos + 1, 1)); return self::negotiate_century_span_bce_ce(\substr($datum, 0, 1), \substr($datum, $dashPos + 1, 1));
} }
} }
// 1-2. Jahrhundert // 1-2. Jahrhundert
if (preg_match("/^[0-9](\.|)(|\ Jh\.||\ Jahrhundert||\ sz||\ század)\-[0-9]\.\ (Jh\.|Jahrhundert|sz|század)$/", $datum)) { if (\preg_match("/^[0-9](\.|)(|\ Jh\.||\ Jahrhundert||\ sz||\ század)\-[0-9]\.\ (Jh\.|Jahrhundert|sz|század)$/", $datum)) {
if (($dashPos = strpos($datum, "-")) !== false) { if (($dashPos = \strpos($datum, "-")) !== false) {
return self::negotiate_century_span_bce_ce(substr($datum, 0, 1), substr($datum, $dashPos + 1, 1)); return self::negotiate_century_span_bce_ce(\substr($datum, 0, 1), \substr($datum, $dashPos + 1, 1));
} }
} }
@ -925,15 +925,15 @@ final class NodaTimeSplitter {
$datum = self::clean_input($datum); $datum = self::clean_input($datum);
$bcBceIndicator = '+'; $bcBceIndicator = '+';
if (preg_match("/^[0-9]0(er|er\ Jahre|\-es\ évek|\-as\ \évek)$/", $datum)) { if (\preg_match("/^[0-9]0(er|er\ Jahre|\-es\ évek|\-as\ \évek)$/", $datum)) {
$start = "19" . substr($datum, 0, 2); $start = "19" . \substr($datum, 0, 2);
$ende = (string)(intval($start) + 9); $ende = (string)(\intval($start) + 9);
return [$start, $ende, "00", "00", $bcBceIndicator, ""]; return [$start, $ende, "00", "00", $bcBceIndicator, ""];
} }
if (preg_match("/^[0-9]{3}0(er|er\ Jahre|\-es\ évek|\-as\ \évek)$/", $datum)) { if (\preg_match("/^[0-9]{3}0(er|er\ Jahre|\-es\ évek|\-as\ \évek)$/", $datum)) {
$start = substr($datum, 0, 4); $start = \substr($datum, 0, 4);
$ende = (string)(intval($start) + 9); $ende = (string)(\intval($start) + 9);
return [$start, $ende, "00", "00", $bcBceIndicator, ""]; return [$start, $ende, "00", "00", $bcBceIndicator, ""];
} }