From e8edb4a4594f59fa252ce20d0cd010e1251747ee Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Sat, 5 Apr 2025 00:09:39 +0200 Subject: [PATCH] Time splitter: Handle first/second half Close #31 --- src/NodaTimeSplitter.php | 9 +++++++++ tests/NodaNameSplitterTest.php | 6 ++++-- tests/NodaTimeSplitterTest.php | 12 ++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/NodaTimeSplitter.php b/src/NodaTimeSplitter.php index 3221980..018bdff 100644 --- a/src/NodaTimeSplitter.php +++ b/src/NodaTimeSplitter.php @@ -1101,6 +1101,15 @@ final class NodaTimeSplitter { if (empty($datum)) return ''; + if (\preg_match("/^1\.\ (Halbjahr|Hälfte)\ [0-9]{4}$/", $datum)) { + $year = substr($datum, -4); + return "Januar $year-Juni $year"; + } + if (\preg_match("/^2\.\ (Halbjahr|Hälfte)\ [0-9]{4}$/", $datum)) { + $year = substr($datum, -4); + return "Juli $year-Dezember $year"; + } + $inputLength = strlen($datum); // Hungarian year and month until month diff --git a/tests/NodaNameSplitterTest.php b/tests/NodaNameSplitterTest.php index c4f2bc4..6a5d513 100644 --- a/tests/NodaNameSplitterTest.php +++ b/tests/NodaNameSplitterTest.php @@ -6,12 +6,14 @@ */ declare(strict_types = 1); use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Small; /** * This script contains tests for the actor name splitter. - * - * @covers \NodaNameSplitter */ +#[Small] +#[CoversClass(\NodaIDGetter::class)] final class NodaNameSplitterTest extends TestCase { /** * Test to check whether the HTML page is correctly generated. diff --git a/tests/NodaTimeSplitterTest.php b/tests/NodaTimeSplitterTest.php index 0c90238..f883d3b 100644 --- a/tests/NodaTimeSplitterTest.php +++ b/tests/NodaTimeSplitterTest.php @@ -509,6 +509,18 @@ final class NodaTimeSplitterTest extends TestCase { "counting_time_day" => "01", "counting_time_bcce" => "+", ], + "1. Halbjahr 1950" => [ + 'start_name' => "Januar 1950", + 'end_name' => "Juni 1950", + "start_year" => '1950', + "end_year" => '1950', + 'start_date' => '1950-01-01', + 'end_date' => '1950-06-31', + "counting_time_year" => "1950", + "counting_time_month" => "04", + "counting_time_day" => "02", + "counting_time_bcce" => "+", + ], ] as $in => $out) { $output[$in] = [$in, $out]; }