Newer
Older
use App\Action\Functions;
use App\Validation\DateValidation;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
class HomeController extends AbstractController
{
private Functions $functions;
public function __construct(Functions $functions)
{
$this->functions = $functions;
#[Route('/{startDate}/{endDate}', name: 'home')] // 01-01-2024
public function home(string $startDate, string $endDate): Response
if (DateValidation::validate($startDate) && DateValidation::validate($endDate)) {
try {
$result = $this->functions->diffDays(
new DateTimeImmutable($startDate),
new DateTimeImmutable($endDate)
);
return $this->json(["The difference of days:" => $result]);
} catch (\Exception $e) {
return new Response($e->getMessage());
}
}
return new Response("Invalid date format");