Enable parsing of months: 2020-01

This commit is contained in:
Joshua Ramon Enslin 2020-09-27 17:10:17 +02:00 committed by Stefan Rohde-Enslin
parent baeb9ba72e
commit 91f435a2e4
2 changed files with 25 additions and 0 deletions

View File

@ -536,6 +536,18 @@ final class NodaTimeSplitter {
unset($start, $month);
}
}
// Intl': 2020-12
if (preg_match("/^[0-9][0-9][0-9][0-9]\-[0-9][0-9]$/", $datum)) { // German Y-m
$start = substr($datum, 0, 4);
$month = substr($datum, 5, 2);
if (intval($month) < 13) {
return [$start, $start, $month, "00", "+", ""];
}
else {
unset($start, $month);
}
}
// German MM.JJJJ
if (preg_match("/^[0-9][0-9]\.[0-9][0-9][0-9][0-9]$/", $datum)) { // German Y-m
$start = substr($datum, 3, 4);

View File

@ -144,6 +144,19 @@ final class NodaTimeSplitterTest extends TestCase {
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Januar 2020");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
// Intl' month: 2020-01
$output = NodaTimeSplitter::attempt_splitting("2020-01");
self::assertEquals($output, [
0 => "2020",
1 => "2020",
2 => "01",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Januar 2020");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
$output = NodaTimeSplitter::attempt_splitting("Januar 2020 v. Chr.");
self::assertEquals($output, [
0 => "-2020",