Prevent splitting of non-existing exact dates (e.g. 31.04.XXXX)
Close #35
This commit is contained in:
		| @@ -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); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user