Teach time splitter to handle multi-year time spans in CE
This commit is contained in:
parent
c298794a32
commit
affe8e3741
@ -162,18 +162,29 @@ final class NodaTimeSplitter {
|
||||
*/
|
||||
public static function timePartsToTimeName(array $moda):string {
|
||||
|
||||
$moda[0] = intval($moda[0]);
|
||||
$moda[1] = intval($moda[1]);
|
||||
|
||||
if ($moda[0] > $moda[1]) {
|
||||
$suffix = " v. Chr.";
|
||||
}
|
||||
else if ($moda[1] < 1000) {
|
||||
$suffix = " n. Chr.";
|
||||
}
|
||||
else $suffix = "";
|
||||
|
||||
if ($moda[0] !== $moda[1]) {
|
||||
return "{$moda[0]}-{$moda[1]}";
|
||||
return "{$moda[0]}-{$moda[1]}{$suffix}";
|
||||
}
|
||||
else if (intval($moda[2]) !== 0 and intval($moda[3]) !== 0) {
|
||||
return "{$moda[3]}.{$moda[2]}.{$moda[0]}";
|
||||
return "{$moda[3]}.{$moda[2]}.{$moda[0]}{$suffix}";
|
||||
}
|
||||
else if ($moda[0] === $moda[1] && trim($moda[2], " 0") === "" && trim($moda[3], " 0") === "") {
|
||||
return "{$moda[0]}";
|
||||
return "{$moda[0]}{$suffix}";
|
||||
}
|
||||
else if ($moda[0] === $moda[1] && trim($moda[2], " 0") !== "" && trim($moda[3], " 0") === "") {
|
||||
setlocale(LC_TIME, NodaTimeAutotranslater::LANGS_TO_LOCALES['de']);
|
||||
return strftime(getMonthFormatByLang("de"), MD_STD::strtotime("{$moda[0]}-{$moda[2]}-01 01:01:01"));
|
||||
return strftime(getMonthFormatByLang("de"), MD_STD::strtotime("{$moda[0]}-{$moda[2]}-01 01:01:01")) . $suffix;
|
||||
}
|
||||
|
||||
return "";
|
||||
@ -415,6 +426,22 @@ final class NodaTimeSplitter {
|
||||
$month = substr($datum, 5, 2);
|
||||
return [$start, $start, $month, "00"];
|
||||
}
|
||||
if (preg_match("/^[0-9][0-9][0-9][0-9]\-[0-9][0-9]$/", $datum)) { // Hungarian Y-m
|
||||
$start = substr($datum, 0, 4);
|
||||
$endDigits = substr($datum, 5, 2);
|
||||
if (intval($endDigits) > 12) return [$start, substr($datum, 0, 2) . $endDigits, "00", "00"];
|
||||
}
|
||||
if (preg_match("/^01\.01\.[0-9][0-9][0-9][0-9]\-31\.12\.[0-9][0-9][0-9][0-9]$/", $datum)) { // Hungarian Y-m
|
||||
$start = substr($datum, 6, 4);
|
||||
$end = substr($datum, -4);
|
||||
return [$start, $end, "00", "00"];
|
||||
}
|
||||
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"];
|
||||
}
|
||||
|
||||
if (preg_match("/^[0-9][0-9][0-9][0-9]$/", $datum)) {
|
||||
|
||||
$start = substr($datum, 0, 4);
|
||||
|
Loading…
Reference in New Issue
Block a user