Enable parsing of months: 2020-01
This commit is contained in:
parent
baeb9ba72e
commit
91f435a2e4
|
@ -536,6 +536,18 @@ final class NodaTimeSplitter {
|
||||||
unset($start, $month);
|
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
|
// German MM.JJJJ
|
||||||
if (preg_match("/^[0-9][0-9]\.[0-9][0-9][0-9][0-9]$/", $datum)) { // German Y-m
|
if (preg_match("/^[0-9][0-9]\.[0-9][0-9][0-9][0-9]$/", $datum)) { // German Y-m
|
||||||
$start = substr($datum, 3, 4);
|
$start = substr($datum, 3, 4);
|
||||||
|
|
|
@ -144,6 +144,19 @@ final class NodaTimeSplitterTest extends TestCase {
|
||||||
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Januar 2020");
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Januar 2020");
|
||||||
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 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.");
|
$output = NodaTimeSplitter::attempt_splitting("Januar 2020 v. Chr.");
|
||||||
self::assertEquals($output, [
|
self::assertEquals($output, [
|
||||||
0 => "-2020",
|
0 => "-2020",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user