diff --git a/src/NodaTimeSplitter.php b/src/NodaTimeSplitter.php index be23a8b..5c83f45 100644 --- a/src/NodaTimeSplitter.php +++ b/src/NodaTimeSplitter.php @@ -48,6 +48,9 @@ final class NodaTimeSplitter { "nach Chr." => "", "n. Chr." => "", "n.Chr." => "", + // To clean + "v.Chr." => "v. Chr.", + "v. Chr" => "v. Chr.", ]; const STOP_STRINGS_GERMAN = [ @@ -114,6 +117,7 @@ final class NodaTimeSplitter { while (strpos($input, " -") !== false) $input = str_replace(" -", "-", $input); while (strpos($input, "- ") !== false) $input = str_replace("- ", "-", $input); $input = strtr($input, self::STRINGS_TO_CLEAN); + while (strpos($input, "..") !== false) $input = str_replace("..", ".", $input); return trim($input, ", [](){}"); @@ -174,7 +178,7 @@ final class NodaTimeSplitter { $moda[0] = intval($moda[0]); $moda[1] = intval($moda[1]); - if ($moda[0] > $moda[1]) { + if ($moda[0] < 0 && $moda[1] < 0) { $suffix = " v. Chr."; } else if ($moda[1] < 1000) { @@ -182,6 +186,9 @@ final class NodaTimeSplitter { } else $suffix = ""; + $moda[0] = abs($moda[0]); + $moda[1] = abs($moda[1]); + if ($moda[0] !== $moda[1]) { return "{$moda[0]}-{$moda[1]}{$suffix}"; } @@ -209,7 +216,7 @@ final class NodaTimeSplitter { */ public static function timePartsToCountingYear(array $moda):int { - return (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))); } @@ -234,7 +241,7 @@ final class NodaTimeSplitter { if (($newTimeName = self::timePartsToTimeName($moda)) !== "") { $output .= "&zeit_name_neu={$newTimeName}"; } - $output .= '&zeit_beginn_neu=' . $moda[0] . '&zeit_ende_neu=' . $moda[1] . '&zeit_zaehlzeit_vorzeichen_neu=%2B&zeit_zaehlzeit_jahr_neu=' . $zaehlzeit_jahr . '&zeit_zaehlzeit_monat_neu=' . $moda[2] . '&zeit_zaehlzeit_tag_neu=' . $moda[3] . '&zeit_status_neu=%2B" class="icons iconsBell buttonLike" id="splitTimeLink">+'; + $output .= '&zeit_beginn_neu=' . $moda[0] . '&zeit_ende_neu=' . $moda[1] . '&zeit_zaehlzeit_vorzeichen_neu=' . urlencode($moda[4]) . '&zeit_zaehlzeit_jahr_neu=' . $zaehlzeit_jahr . '&zeit_zaehlzeit_monat_neu=' . $moda[2] . '&zeit_zaehlzeit_tag_neu=' . $moda[3] . '&zeit_status_neu=%2B" class="icons iconsBell buttonLike" id="splitTimeLink">+'; if (!empty($newTimeName)) { $output .= $newTimeName; @@ -282,6 +289,12 @@ 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)) { + $start = "-" . substr($datum, 0, 4); + $end = "-" . substr($datum, 5, 4); + return [$start, $end, "00", "00", "-"]; + } + if (self::stri_occurs($datum, self::STOP_STRINGS_GERMAN)) { return []; } @@ -396,65 +409,63 @@ 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]$/", $datum)) { - $start = substr($datum, 0, 4); $end = substr($datum, -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]$/", $datum)) { // German T.MM.JJJJ $start = substr($datum, 5, 4); $month = "0" . substr($datum, 3, 1); $day = substr($datum, 0, 2); - return [$start, $start, $month, $day]; + return [$start, $start, $month, $day, "+"]; } if (preg_match("/^[0-9]\.[0-9][0-9]\.[0-9][0-9][0-9][0-9]$/", $datum)) { // German T.MM.JJJJ $start = substr($datum, 5, 4); $month = substr($datum, 2, 2); $day = "0" . substr($datum, 0, 1); - return [$start, $start, $month, $day]; + return [$start, $start, $month, $day, "+"]; } if (preg_match("/^[0-9]\.[0-9]\.[0-9][0-9][0-9][0-9]$/", $datum)) { // German T.M.JJJJ $start = substr($datum, 4, 4); $month = "0" . substr($datum, 2, 1); $day = "0" . substr($datum, 0, 1); - return [$start, $start, $month, $day]; + return [$start, $start, $month, $day, "+"]; } if (preg_match("/^[0-9][0-9]\.[0-9][0-9][0-9][0-9]$/", $datum)) { // German Y-m $start = substr($datum, 3, 4); $month = substr($datum, 0, 2); - return [$start, $start, $month, "00"]; + return [$start, $start, $month, "00", "+"]; } if (preg_match("/^[0-9]\.[0-9][0-9][0-9][0-9]$/", $datum)) { // German Y-m $start = substr($datum, 2, 4); $month = "0" . substr($datum, 0, 1); - return [$start, $start, $month, "00"]; + 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); $month = substr($datum, 5, 2); - return [$start, $start, $month, "00"]; + 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 (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"]; + 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 ($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); - return [$start, $start, "00", "00"]; + return [$start, $start, "00", "00", "+"]; } return [];