Split more time variations

This commit is contained in:
Joshua Ramon Enslin 2020-10-04 23:57:59 +02:00 committed by Stefan Rohde-Enslin
parent 8a4a8f7ed8
commit 97566ea2d9

View File

@ -339,6 +339,19 @@ final class NodaTimeSplitter {
}
/**
* Pads to four digits. E.g. 2 > 02.
*
* @param string $input Input string.
*
* @return string
*/
public static function pad_to_two(string $input):string {
return substr("00" . $input, -2);
}
/**
* Translate German month to two digits number.
*
@ -586,6 +599,12 @@ final class NodaTimeSplitter {
$month = "0" . substr($datum, 0, 1);
return [$start, $start, $month, "00", "+", ""];
}
if (preg_match("/^[0-9]{4}\.[0-9]{2}\.[0-9]{1,2}(\.|)$/", $datum)) { // Hungarian Y-m-d
$start = substr($datum, 0, 4);
$month = substr($datum, 5, 2);
$day = self::pad_to_two(substr($datum, 8, 2));
if (intval($month) < 13) return [$start, $start, $month, $day, "+", ""];
}
if (preg_match("/^[0-9]{4}\.[0-9]{2}(\.|)$/", $datum)) { // Hungarian Y-m
$start = substr($datum, 0, 4);
$month = substr($datum, 5, 2);
@ -642,6 +661,15 @@ final class NodaTimeSplitter {
return [$start, $start, "00", "00", "+", ""];
}
// Special case for SMB: YYYY, MM. DD and YYYY, MM.
if (preg_match("/^[0-9]{4}\,\ [0-9]{2}\.(|\ [0-9]{2})$/", $datum)) {
$start = substr($datum, 0, 4);
$month = substr($datum, 6, 2);
$day = self::pad_to_two(substr($datum, 10, 2));
return [$start, $start, $month, $day, "+", ""];
}
return [];
}
@ -738,7 +766,7 @@ final class NodaTimeSplitter {
}
}
if (preg_match("/\ (\(vor|Vor)$/", $datum)) {
if (preg_match("/\ (\(vor|\(Vor|vor)$/", $datum)) {
if (($spacePos = strpos($datum, " ")) === false) {
return [];
}
@ -863,12 +891,16 @@ final class NodaTimeSplitter {
}
// 1.-12. Jahrhundert
if (preg_match("/^[0-9]\.\-[0-9]{2}\.\ (Jh\.|Jahrhundert|sz|század)$/", $datum)) {
return self::negotiate_century_span_bce_ce(substr($datum, 0, 1), substr($datum, 3, 2));
if (preg_match("/^[0-9](\.|)(|\ Jh\.||\ Jahrhundert||\ sz||\ század)\-[0-9]{2}\.\ (Jh\.|Jahrhundert|sz|század)$/", $datum)) {
if (($dashPos = strpos($datum, "-")) !== false) {
return self::negotiate_century_span_bce_ce(substr($datum, 0, 1), substr($datum, $dashPos + 1, 2));
}
}
// 1.-2. Jahrhundert
if (preg_match("/^[0-9]\.\-[0-9]\.\ (Jh\.|Jahrhundert|sz|század)$/", $datum)) {
return self::negotiate_century_span_bce_ce(substr($datum, 0, 1), substr($datum, 3, 1));
if (preg_match("/^[0-9](\.|)(|\ Jh\.||\ Jahrhundert||\ sz||\ század)\-[0-9]\.\ (Jh\.|Jahrhundert|sz|század)$/", $datum)) {
if (($dashPos = strpos($datum, "-")) !== false) {
return self::negotiate_century_span_bce_ce(substr($datum, 0, 1), substr($datum, $dashPos + 1, 1));
}
}
// 1-2. Jahrhundert
if (preg_match("/^[0-9](\.|)(|\ Jh\.||\ Jahrhundert||\ sz||\ század)\-[0-9]\.\ (Jh\.|Jahrhundert|sz|század)$/", $datum)) {