Allow splitting timespans BC.E.
This commit is contained in:
parent
7bc5bdf335
commit
68d07c03d8
|
@ -51,6 +51,7 @@ final class NodaTimeSplitter {
|
|||
// To clean
|
||||
"v.Chr." => "v. Chr.",
|
||||
"v. Chr" => "v. Chr.",
|
||||
"vor Christus" => "v. Chr.",
|
||||
];
|
||||
|
||||
const STOP_STRINGS_GERMAN = [
|
||||
|
@ -249,7 +250,7 @@ final class NodaTimeSplitter {
|
|||
*/
|
||||
public static function generateDisassemblyForDay(int $znum, array $moda, MDTlLoader $tlLoader):string {
|
||||
|
||||
$zaehlzeit_jahr = self::timePartsToCountingYear($moda);
|
||||
$zaehlzeit_jahr = self::pad_to_four((string)self::timePartsToCountingYear($moda));
|
||||
|
||||
// Wenn Datum in Form von tt.mm.jjjj, dann biete zerlegen an
|
||||
$output = '<hr>';
|
||||
|
@ -296,6 +297,19 @@ final class NodaTimeSplitter {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Pads to four digits. E.g. 20 > 0020.
|
||||
*
|
||||
* @param string $input Input string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function pad_to_four(string $input):string {
|
||||
|
||||
return substr("0000" . $input, -4);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate German month to two digits number.
|
||||
*
|
||||
|
@ -307,30 +321,17 @@ final class NodaTimeSplitter {
|
|||
|
||||
$datum = self::clean_input($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)) {
|
||||
$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)) {
|
||||
$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)) {
|
||||
$start = "-00" . substr($datum, 0, 2);
|
||||
$end = "-00" . substr($datum, 3, 2);
|
||||
return [$start, $end, "00", "00", "-", ""];
|
||||
if (preg_match("/\ v\.\ Chr\.$/", $datum)) {
|
||||
if ($output = self::attempt_splitting(substr($datum, 0, -8))) {
|
||||
$start = strval(-1 * intval($output[1]));
|
||||
$end = strval(-1 * intval($output[0]));
|
||||
if (intval($start) > intval($end)) {
|
||||
$startToSet = $end;
|
||||
$end = $start;
|
||||
$start = $startToSet;
|
||||
}
|
||||
return [$start, $end, $output[2], $output[3], '-'];
|
||||
}
|
||||
}
|
||||
|
||||
$datum = str_replace(". ", ".", $datum);
|
||||
|
@ -382,6 +383,11 @@ final class NodaTimeSplitter {
|
|||
if ($output = self::attempt_splitting(substr($datum, 7))) {
|
||||
$start = strval(-1 * intval($output[1]));
|
||||
$end = strval(-1 * intval($output[0]));
|
||||
if (intval($start) > intval($end)) {
|
||||
$startToSet = $end;
|
||||
$end = $start;
|
||||
$start = $startToSet;
|
||||
}
|
||||
return [$start, $end, $output[2], $output[3], '-'];
|
||||
}
|
||||
}
|
||||
|
@ -463,6 +469,7 @@ final class NodaTimeSplitter {
|
|||
|
||||
$datum = self::clean_input($datum);
|
||||
|
||||
// 0000-0000
|
||||
if (preg_match("/^[0-9][0-9][0-9][0-9](\-|\/)[0-9][0-9][0-9][0-9]$/", $datum)
|
||||
|| preg_match("/^[0-9][0-9][0-9][0-9](\-|\/)[0-9][0-9][0-9][0-9]\.$/", $datum)
|
||||
) {
|
||||
|
@ -470,6 +477,14 @@ final class NodaTimeSplitter {
|
|||
$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][0-9]$/", $datum)) {
|
||||
$datum = str_replace(".", "", $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]$/", $datum)) { // German T.MM.JJJJ
|
||||
$start = substr($datum, 5, 4);
|
||||
$month = "0" . substr($datum, 3, 1);
|
||||
|
@ -518,14 +533,21 @@ final class NodaTimeSplitter {
|
|||
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", "+", ""];
|
||||
return ["0" . $start, "0" . $end, "00", "00", "+", ""];
|
||||
}
|
||||
|
||||
// 1720-120
|
||||
if (preg_match("/^[0-9][0-9][0-9][0-9]\-[0-9][0-9][0-9]$/", $datum)) { // Hungarian Y-m
|
||||
$start = substr($datum, 0, 4);
|
||||
$end = substr($datum, -3);
|
||||
return ["0" . $start, "0" . $end, "00", "00", "+", ""];
|
||||
}
|
||||
|
||||
// 20-30 (n. Chr.)
|
||||
if (preg_match("/^[0-9][0-9]\-[0-9][0-9]$/", $datum)) { // 20-40 (n. Chr.)
|
||||
$start = substr($datum, 0, 2);
|
||||
$end = substr($datum, -2);
|
||||
if ($end > $start) return ["00" . $start, "00" . $end, "00", "00", "+", ""];
|
||||
return ["00" . $start, "00" . $end, "00", "00", "+", ""];
|
||||
}
|
||||
|
||||
// 1920
|
||||
|
@ -540,6 +562,11 @@ final class NodaTimeSplitter {
|
|||
return [$start, $start, "00", "00", "+", ""];
|
||||
}
|
||||
|
||||
if (preg_match("/^[0-9][0-9]$/", $datum)) {
|
||||
$start = "00" . substr($datum, 0, 2);
|
||||
return [$start, $start, "00", "00", "+", ""];
|
||||
}
|
||||
|
||||
return [];
|
||||
|
||||
}
|
||||
|
@ -634,6 +661,27 @@ final class NodaTimeSplitter {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Negotiates century spans before times.
|
||||
*
|
||||
* @param string $start Begin time.
|
||||
* @param string $end End time.
|
||||
*
|
||||
* @return array<integer>
|
||||
*/
|
||||
public static function negotiate_century_span_bce_ce(string $start, string $end):array {
|
||||
|
||||
$start = intval($start);
|
||||
$end = intval($end);
|
||||
|
||||
if ($start < $end) {
|
||||
return [(string)($start - 1) . "01", $end . "00", "00", "00", "+", ""];
|
||||
}
|
||||
|
||||
return [(string)($start) . "00", ($end - 1) . "01", "00", "00", "+", ""];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an input date is a century.
|
||||
*
|
||||
|
@ -665,17 +713,24 @@ final class NodaTimeSplitter {
|
|||
|
||||
// 17.-18. Jahrhundert
|
||||
if (preg_match("/^[0-9][0-9]\.\-[0-9][0-9]\.\ (Jh\.|Jahrhundert|század)$/", $datum)) {
|
||||
return [(string)(intval(substr($datum, 0, 2)) - 1) . "01", substr($datum, 4, 2) . "00", "00", "00", $bcBceIndicator, ""];
|
||||
return self::negotiate_century_span_bce_ce(substr($datum, 0, 2), substr($datum, 4, 2));
|
||||
}
|
||||
// 17-18. Jahrhundert
|
||||
if (preg_match("/^[0-9][0-9]\-[0-9][0-9]\.\ (Jh\.|Jahrhundert|század)$/", $datum)) {
|
||||
return [(string)(intval(substr($datum, 0, 2)) - 1) . "01", substr($datum, 3, 2) . "00", "00", "00", $bcBceIndicator, ""];
|
||||
return self::negotiate_century_span_bce_ce(substr($datum, 0, 2), substr($datum, 3, 2));
|
||||
}
|
||||
|
||||
if (preg_match("/^[0-9]\.\-[0-9]\.\ (Jh\.|Jahrhundert|század)$/", $datum)) {
|
||||
return [(string)(intval(substr($datum, 0, 1)) - 1) . "01", substr($datum, 3, 1) . "00", "00", "00", $bcBceIndicator, ""];
|
||||
// 1.-12. Jahrhundert
|
||||
if (preg_match("/^[0-9]\.\-[0-9][0-9]\.\ (Jh\.|Jahrhundert|század)$/", $datum)) {
|
||||
return self::negotiate_century_span_bce_ce(substr($datum, 0, 1), substr($datum, 3, 2));
|
||||
}
|
||||
// 1.-2. Jahrhundert
|
||||
if (preg_match("/^[0-9]\.\-[0-9]\.\ (Jh\.|Jahrhundert|század)$/", $datum)) {
|
||||
return self::negotiate_century_span_bce_ce(substr($datum, 0, 1), substr($datum, 3, 1));
|
||||
}
|
||||
// 1-2. Jahrhundert
|
||||
if (preg_match("/^[0-9]\-[0-9]\.\ (Jh\.|Jahrhundert|század)$/", $datum)) {
|
||||
return [(string)(intval(substr($datum, 0, 1)) - 1) . "01", substr($datum, 2, 1) . "00", "00", "00", $bcBceIndicator, ""];
|
||||
return self::negotiate_century_span_bce_ce(substr($datum, 0, 1), substr($datum, 2, 1));
|
||||
}
|
||||
|
||||
return [];
|
||||
|
|
Loading…
Reference in New Issue
Block a user