diff --git a/web/mrbs_sql.inc b/web/mrbs_sql.inc index 8c2d4412c..76e6a13be 100644 --- a/web/mrbs_sql.inc +++ b/web/mrbs_sql.inc @@ -601,20 +601,19 @@ function mrbsCheckPolicy(array $booking, ?int $ignore_entry_id=null, ?int $ignor // Check min_booking_date if ($min_booking_date_enabled && !$delete) { - list($y, $m, $d) = explode('-', $min_booking_date); - if (isset($y) && isset($m) && isset($d) && checkdate($m, $d, $y)) + // Use DateTimeImmutable because we will need the original date for the error message + $date_immutable = DateTimeImmutable::createFromFormat($format='Y-m-d', $min_booking_date); + // Check that the date is valid (createFromFormat will allow, for example, months > 12) + if (($date_immutable === false) || ($date_immutable->format($format) !== $min_booking_date)) { - if ($booking['start_time'] < mktime(0, 0, 0, $m, $d, $y)) - { - $violations[] = get_vocab( - 'earliest_booking_date', - datetime_format($datetime_formats['date'], mktime(0, 0, 0, $m, $d, $y)) - ); - } + throw new \Exception('MRBS config error: invalid $min_booking_date ' . "'$min_booking_date'"); } - else + if ($booking['start_time'] < $date_immutable->setTime(0, 0)->getTimestamp()) { - trigger_error("Invalid min_book_ahead_date", E_USER_NOTICE); + $violations[] = get_vocab( + 'earliest_booking_date', + datetime_format($datetime_formats['date'], $date_immutable->getTimestamp()) + ); } }