From 9c2eaa2929f389aeea98aeaf702bc46a03534c9e Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Wed, 15 Jan 2025 10:35:35 +0100 Subject: [PATCH] Allow splitting 1945-48 --- src/NodaTimeSplitter.php | 12 ++++++++++-- tests/NodaTimeSplitterTest.php | 13 +++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/NodaTimeSplitter.php b/src/NodaTimeSplitter.php index e691ce3..c946744 100644 --- a/src/NodaTimeSplitter.php +++ b/src/NodaTimeSplitter.php @@ -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 diff --git a/tests/NodaTimeSplitterTest.php b/tests/NodaTimeSplitterTest.php index 0547bd0..0b3dc22 100644 --- a/tests/NodaTimeSplitterTest.php +++ b/tests/NodaTimeSplitterTest.php @@ -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(), [