Allow splitting 1945-48

This commit is contained in:
Joshua Ramon Enslin 2025-01-15 10:35:35 +01:00
parent 546c17031a
commit 9c2eaa2929
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE
2 changed files with 23 additions and 2 deletions

View File

@ -590,10 +590,18 @@ final class NodaTimeSplitter {
return NodaSplitTime::genExactDate($year, $month, $day);
}
// Intl': 2020-12
if (\preg_match("/^[0-9]{4}\-[0-9]{2}$/", $datum)) { // German Y-m
if (\preg_match("/^[0-9]{4}\-[0-9]{2}$/", $datum)) { // German Y-m or 1912-15
$year = \substr($datum, 0, 4);
$month = \substr($datum, 5, 2);
return new NodaSplitTime($year, $year, $month);
// Assume the end is a month
if (intval($month) < 12) {
return new NodaSplitTime($year, $year, $month);
}
else {
$end = \substr($year, 0, 2) . $month;
return new NodaSplitTime($year, $end);
}
}
// German MM.JJJJ

View File

@ -450,6 +450,19 @@ final class NodaTimeSplitterTest extends TestCase {
self::assertEquals($output->toTimeName(), "1901-2000");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1951);
$output = NodaTimeSplitter::attempt_splitting("1945-48");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "1945",
1 => "1948",
2 => "00",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "1945-1948");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1947);
$output = NodaTimeSplitter::attempt_splitting("20.-19. Jahrhundert v. Chr.");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [