From 1051e10732a6f4a4e76099506031e8cc8a06952e Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Tue, 6 May 2025 22:32:00 +0200 Subject: [PATCH] Prevent ambigious splitting of [0-9]{4}-[0-9]{2} --- src/NodaTimeSplitter.php | 6 ++++++ tests/NodaTimeSplitterTest.php | 1 + 2 files changed, 7 insertions(+) diff --git a/src/NodaTimeSplitter.php b/src/NodaTimeSplitter.php index 33c6e1c..8ab32bc 100644 --- a/src/NodaTimeSplitter.php +++ b/src/NodaTimeSplitter.php @@ -609,6 +609,12 @@ final class NodaTimeSplitter { // Assume the end is a month if (intval($month) < 12) { + // If the year is smaller than the second number, do not split, as either month + // or year may be meant + // Example: 1903-04 + if (substr($datum, 2, 2) < 12) { + return false; + } return new NodaSplitTime($year, $year, $month); } else { diff --git a/tests/NodaTimeSplitterTest.php b/tests/NodaTimeSplitterTest.php index 405d827..82175df 100644 --- a/tests/NodaTimeSplitterTest.php +++ b/tests/NodaTimeSplitterTest.php @@ -604,6 +604,7 @@ final class NodaTimeSplitterTest extends TestCase { "13.13.2022", "2022-13-13", "40.10.2022", + "1903-04", "1903/04", "2022-10-40", "6;November 1978",