Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Commit

Permalink
correctly handle broken date parameters in public forecast URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierlacot committed Aug 2, 2023
1 parent ac39ace commit 0bfcd8e
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/Controller/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,27 @@ public function forecastIcal(Builder $forecastBuilder, PublicForecast $publicFor
#[Route(path: '/forecast/{token}/{start}/{end}', name: 'public_forecast_start_end')]
public function forecast(Builder $forecastBuilder, PublicForecast $publicForecast, $start = null, $end = null): Response
{
if (null === $start) {
$start = new \DateTime('first day of last month');
} else {
$start = new \DateTime($start);
}
try {
if (null === $start) {
$start = new \DateTime('first day of last month');
} else {
$start = new \DateTime($start);
}

if (null === $end) {
$end = new \DateTime('last day of next month');
} else {
$end = new \DateTime($end);
if (null === $end) {
$end = new \DateTime('last day of next month');
} else {
$end = new \DateTime($end);
}
} catch (\Exception) {
return $this->render('home/public-forecast.html.twig', [
'assignments' => [],
'error' => 'The "start" and "end" data URL parameters must be of the form YYYY-MM-DD.',
'start' => null,
'end' => null,
'today' => (new \DateTime())->format('Y-m-d'),
'publicForecast' => $publicForecast,
]);
}

if ($start >= $end) {
Expand Down

0 comments on commit 0bfcd8e

Please sign in to comment.