Skip to content

Commit

Permalink
Fix TypeError when using $min_booking_date. See GitHub Issue #3773.
Browse files Browse the repository at this point in the history
  • Loading branch information
campbell-m committed Nov 8, 2024
1 parent a4be571 commit 9977616
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions web/mrbs_sql.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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())
);
}
}

Expand Down

0 comments on commit 9977616

Please sign in to comment.