diff --git a/src/NodaSplitTime.php b/src/NodaSplitTime.php index 1228ffe..7623abb 100644 --- a/src/NodaSplitTime.php +++ b/src/NodaSplitTime.php @@ -28,9 +28,10 @@ final class NodaSplitTime { /** * Returns a single, exact date. * - * @param string $year Year. - * @param string $month Month. - * @param string $day Day. + * @param string $year Year. + * @param string $month Month. + * @param string $day Day. + * @param NodaTimeBeforeAfterIndicator $before_after_indicator Determines if the time is exact or before / after. * * @return NodaSplitTime */ @@ -296,6 +297,15 @@ final class NodaSplitTime { /** * Constructor. * + * @param string $start_year Year. + * @param string $end_year Year. + * @param string $counting_time_month Month. + * @param string $counting_time_day Day. + * @param NodaCountingTimeIndicator $counting_time_indicator Determines if the time is BCE or CCE. + * @param NodaTimeBeforeAfterIndicator $before_after_indicator Determines if the time is inexact to one direction. + * @param false|string $start_date Start date. + * @param false|string $end_date End date. + * * @return void */ public function __construct(string $start_year, string $end_year, @@ -379,5 +389,19 @@ final class NodaSplitTime { } } + // Validate + $startDateTime = MD_STD::strtotime("2000-" . substr($this->start_date, -5)); + if (checkdate((int)date('m', $startDateTime), (int)date('d', $startDateTime), (int)date('Y', $startDateTime)) === false) { + throw new MDgenericInvalidInputsException("Invalid start date: " . $this->start_date); + } + + if (!empty((int)$this->counting_time_day)) { + // The year 2000 is used here as it is a leap year and lots of years accepted in md are not accepted + // by checkdate. + if (checkdate((int)$this->counting_time_month, (int)$this->counting_time_day, 2000) === false) { + throw new MDgenericInvalidInputsException("Invalid date formed by counting time: " . $this->counting_time_month . ' -- ' . $this->counting_time_day); + } + } + } } diff --git a/tests/NodaTimeSplitterTest.php b/tests/NodaTimeSplitterTest.php index cefa09c..3f03bef 100644 --- a/tests/NodaTimeSplitterTest.php +++ b/tests/NodaTimeSplitterTest.php @@ -550,6 +550,9 @@ final class NodaTimeSplitterTest extends TestCase { ]; foreach ([ + "30.02.2024", + "31.11.2024", + "31.4.2024", "1.2.2020-2.2.2020", "2020 Januar 2-2020 Februar 2", "2020 Januar-2020 Februar",