From 7d303e219f5059afdb0006850a3adb4ffbe7c574 Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Sat, 4 May 2024 01:17:33 +0200 Subject: [PATCH] Fix broken time splitting for year ranges BC --- src/NodaSplitTime.php | 1 + src/NodaTimeSplitter.php | 6 +++++- tests/NodaTimeSplitterTest.php | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/NodaSplitTime.php b/src/NodaSplitTime.php index d773d03..d8f8351 100644 --- a/src/NodaSplitTime.php +++ b/src/NodaSplitTime.php @@ -330,6 +330,7 @@ final class NodaSplitTime { $this->end_date = '9999-12-31'; } + if (!isset($this->start_date) && false !== $start_date) { $this->start_date = date("Y-m-d", MD_STD::strtotime($start_date)); } diff --git a/src/NodaTimeSplitter.php b/src/NodaTimeSplitter.php index 44572f0..b8bfb80 100644 --- a/src/NodaTimeSplitter.php +++ b/src/NodaTimeSplitter.php @@ -336,13 +336,17 @@ final class NodaTimeSplitter { $start = \strval(-1 * \intval($output->end_year)); $end = \strval(-1 * \intval($output->start_year)); + $start_date = $output->end_date; + $end_date = $output->start_date; if (\intval($start) > \intval($end)) { $startToSet = $end; $end = $start; $start = $startToSet; + $start_date = $output->start_date; + $end_date = $output->end_date; } return new NodaSplitTime($start, $end, $output->counting_time_month, $output->counting_time_day, - NodaCountingTimeIndicator::bce, $output->before_after_indicator, '-' . $output->end_date, '-' . $output->start_date); + NodaCountingTimeIndicator::bce, $output->before_after_indicator, '-' . $start_date, '-' . $end_date); } } diff --git a/tests/NodaTimeSplitterTest.php b/tests/NodaTimeSplitterTest.php index e49e277..edd45de 100644 --- a/tests/NodaTimeSplitterTest.php +++ b/tests/NodaTimeSplitterTest.php @@ -928,6 +928,8 @@ final class NodaTimeSplitterTest extends TestCase { 'end_name' => "Februar 2004", "start_year" => '2004', "end_year" => '2004', + 'start_date' => '2004-01-01', + 'end_date' => '2004-02-31', "counting_time_year" => "2004", "counting_time_month" => "02", "counting_time_day" => "01", @@ -942,6 +944,8 @@ final class NodaTimeSplitterTest extends TestCase { 'end_name' => "Februar 2004", "start_year" => '2004', "end_year" => '2004', + 'start_date' => '2004-01-01', + 'end_date' => '2004-02-31', "counting_time_year" => "2004", "counting_time_month" => "02", "counting_time_day" => "01", @@ -963,6 +967,8 @@ final class NodaTimeSplitterTest extends TestCase { 'end_name' => "15.04.2019", "start_year" => '2019', "end_year" => '2019', + 'start_date' => '2019-03-14', + 'end_date' => '2019-04-15', "counting_time_year" => "2019", "counting_time_month" => "03", "counting_time_day" => "30", @@ -976,6 +982,8 @@ final class NodaTimeSplitterTest extends TestCase { 'end_name' => "15.03.2019", "start_year" => '2019', "end_year" => '2019', + 'start_date' => '2019-03-14', + 'end_date' => '2019-03-15', "counting_time_year" => "2019", "counting_time_month" => "03", "counting_time_day" => "15", @@ -990,6 +998,8 @@ final class NodaTimeSplitterTest extends TestCase { 'end_name' => "1900", "start_year" => '1601', "end_year" => '1900', + 'start_date' => '1601-01-01', + 'end_date' => '1900-12-31', "counting_time_year" => "1751", "counting_time_month" => "01", "counting_time_day" => "01", @@ -1004,12 +1014,19 @@ final class NodaTimeSplitterTest extends TestCase { 'end_name' => "1969", "start_year" => '1950', "end_year" => '1969', + 'start_date' => '1950-01-01', + 'end_date' => '1969-12-31', "counting_time_year" => "1960", "counting_time_month" => "01", "counting_time_day" => "01", "counting_time_bcce" => "+", ]); + // Rewritten / 1950-60-as évek + $output = NodaTimeSplitter::attempt_splitting("1400-1100 v. Chr."); + self::assertEquals('-1400', $output->start_year); + self::assertEquals('-1400-01-01', $output->start_date); + } /**