From 1a7dbcd6f62d79fa5a720cfee4059320cc7b21c1 Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Tue, 7 Nov 2023 00:27:20 +0100 Subject: [PATCH] Fix edge cases in time splitter where inputs start with many digits but are not dates --- src/NodaTimeSplitter.php | 5 ++++- tests/NodaTimeSplitterTest.php | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/NodaTimeSplitter.php b/src/NodaTimeSplitter.php index 6a9cbc0..ba6d287 100644 --- a/src/NodaTimeSplitter.php +++ b/src/NodaTimeSplitter.php @@ -514,10 +514,13 @@ final class NodaTimeSplitter { // Further code requires a year to be present, skip if none is set if (empty($year)) return []; + // Skip, if dates are too long and do not contain spaces (= no translatable names) + if (str_contains($datum, " ") === false && strlen($datum) > 12) return []; + foreach (self::MONTH_NAMES_HUNGARIAN as $monthVal => $monthValidNames) { if (self::stri_occurs($datum, $monthValidNames)) { - if (!empty($monat)) return []; $monat = (string)$monthVal; + break; } } diff --git a/tests/NodaTimeSplitterTest.php b/tests/NodaTimeSplitterTest.php index 99bdef7..67324a7 100644 --- a/tests/NodaTimeSplitterTest.php +++ b/tests/NodaTimeSplitterTest.php @@ -695,6 +695,9 @@ final class NodaTimeSplitterTest extends TestCase { $output = NodaTimeSplitter::attempt_splitting("6;November 1978"); self::assertEquals($output, []); + $output = NodaTimeSplitter::attempt_splitting("65497028c51eb"); + self::assertEquals($output, []); + # $output = NodaTimeSplitter::attempt_splitting("Nach 1944-1964"); # self::assertEquals($output, []);