Enable time splitter to deal with some roman numbers
This commit is contained in:
parent
80cd88222d
commit
ff35ca7bd9
@ -54,6 +54,14 @@ final class NodaTimeSplitter {
|
||||
"vor Christus" => "v. Chr.",
|
||||
];
|
||||
|
||||
const STRINGS_TO_CLEAN_START = [
|
||||
"V. " => "5. ",
|
||||
"IV. " => "4. ",
|
||||
"III. " => "3. ",
|
||||
"II. " => "2. ",
|
||||
"I. " => "1. ",
|
||||
];
|
||||
|
||||
const STOP_STRINGS_GERMAN = [
|
||||
"-",
|
||||
",",
|
||||
@ -118,6 +126,11 @@ 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);
|
||||
foreach (self::STRINGS_TO_CLEAN_START as $toCleanFrom => $toCleanTo) {
|
||||
if (strpos($input, $toCleanFrom) === 0) {
|
||||
$input = str_replace($toCleanFrom, $toCleanTo, $input);
|
||||
}
|
||||
}
|
||||
while (strpos($input, "..") !== false) $input = str_replace("..", ".", $input);
|
||||
|
||||
return trim($input, ", [](){}");
|
||||
@ -752,7 +765,6 @@ final class NodaTimeSplitter {
|
||||
|
||||
// 1. Jahrhundert
|
||||
if (preg_match("/^[0-9]\.\ (Jh\.|Jahrhundert|sz|század)$/", $datum)) {
|
||||
echo "HI";
|
||||
if ($centuryNo = intval(substr($datum, 0, 1))) {
|
||||
$centuryNo--;
|
||||
return [(string)$centuryNo . "01", strval($centuryNo + 1) . "00", "00", "00", $bcBceIndicator, ""];
|
||||
|
@ -362,6 +362,18 @@ final class NodaTimeSplitterTest extends TestCase {
|
||||
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1901-2000");
|
||||
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1951);
|
||||
|
||||
$output = NodaTimeSplitter::attempt_splitting("III. század");
|
||||
self::assertEquals($output, [
|
||||
0 => "201",
|
||||
1 => "300",
|
||||
2 => "00",
|
||||
3 => "00",
|
||||
4 => "+",
|
||||
5 => "",
|
||||
]);
|
||||
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "201-300 n. Chr.");
|
||||
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 251);
|
||||
|
||||
$output = NodaTimeSplitter::attempt_splitting("20. század");
|
||||
self::assertEquals($output, [
|
||||
0 => "1901",
|
||||
|
Loading…
Reference in New Issue
Block a user