diff --git a/src/Condition/BaseDateRangeConditionRule.php b/src/Condition/BaseDateRangeConditionRule.php index 11337026af0..5a683215c98 100644 --- a/src/Condition/BaseDateRangeConditionRule.php +++ b/src/Condition/BaseDateRangeConditionRule.php @@ -16,6 +16,7 @@ use CraftCms\Cms\Support\Url; use DateTimeInterface; use Exception; +use Illuminate\Support\Facades\Date; use Illuminate\Validation\Rule; use Override; @@ -379,6 +380,12 @@ protected function matchValue(?DateTimeInterface $value): bool private function _inclusiveEndDate(): DateTimeInterface { - return DateTimeHelper::toDateTime($this->_endDate)->modify('+1 day'); + $endDate = DateTimeHelper::toDateTime($this->_endDate); + + if ($endDate === false) { + throw new Exception('Invalid end date.'); + } + + return Date::instance($endDate)->modify('+1 day'); } } diff --git a/src/Support/DateTimeHelper.php b/src/Support/DateTimeHelper.php index 89685fecb19..71e349adb34 100644 --- a/src/Support/DateTimeHelper.php +++ b/src/Support/DateTimeHelper.php @@ -72,11 +72,11 @@ class DateTimeHelper * @param bool $assumeSystemTimeZone Whether it should be assumed that the value was set in the system timezone if * the timezone was not specified. If this is `false`, UTC will be assumed. * @param bool $setToSystemTimeZone Whether to set the resulting DateTime object to the system timezone. - * @return DateTime|false The DateTime object, or `false` if $object could not be converted to one + * @return DateTimeInterface|false The DateTime object, or `false` if $object could not be converted to one * * @throws Exception */ - public static function toDateTime(mixed $value, bool $assumeSystemTimeZone = false, bool $setToSystemTimeZone = true): DateTime|false + public static function toDateTime(mixed $value, bool $assumeSystemTimeZone = false, bool $setToSystemTimeZone = true): DateTimeInterface|false { if ($value instanceof DateTime) { return $value;