Skip to content

Commit

Permalink
Fix TypeError when using $max_booking_date. See GitHub Issue #3772.
Browse files Browse the repository at this point in the history
  • Loading branch information
campbell-m committed Nov 7, 2024
1 parent 71bd92b commit a4be571
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions web/mrbs_sql.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
declare(strict_types=1);
namespace MRBS;

use DateTimeImmutable;
use MRBS\ICalendar\RFC5545;

define('INTERVAL_DAY', 0);
Expand Down Expand Up @@ -620,20 +621,19 @@ function mrbsCheckPolicy(array $booking, ?int $ignore_entry_id=null, ?int $ignor
// Check max_booking_date
if ($max_booking_date_enabled && !$delete)
{
list($y, $m, $d) = explode('-', $max_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', $max_booking_date);
// Check that the date is valid (createFromFormat will allow, for example, months > 12)
if (($date_immutable === false) || ($date_immutable->format($format) !== $max_booking_date))
{
if ($booking['end_time'] > mktime(0, 0, 0, $m, $d+1, $y))
{
$violations[] = get_vocab(
'latest_booking_date',
datetime_format($datetime_formats['date'], mktime(0, 0, 0, $m, $d, $y))
);
}
throw new \Exception('MRBS config error: invalid $max_booking_date ' . "'$max_booking_date'");
}
else
if ($booking['end_time'] > $date_immutable->setTime(0, 0)->modify('+1 day')->getTimestamp())
{
trigger_error("Invalid max_book_ahead_date", E_USER_NOTICE);
$violations[] = get_vocab(
'latest_booking_date',
datetime_format($datetime_formats['date'], $date_immutable->getTimestamp())
);
}
}

Expand Down

1 comment on commit a4be571

@reneechong12
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I believe min_booking_date has the same issue, although I didn't use it.

Please sign in to comment.