Skip to content
Snippets Groups Projects
HomeController.php 812 B
Newer Older
Адлан Шамавов's avatar
Адлан Шамавов committed
<?php

namespace App\Controller;

use DateInterval;
use DatePeriod;
use DateTime;
Адлан Шамавов's avatar
Адлан Шамавов committed
use DateTimeImmutable;
Адлан Шамавов's avatar
Адлан Шамавов committed
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;

class HomeController extends AbstractController
{
Адлан Шамавов's avatar
Адлан Шамавов committed
    private function diffDays(DateTimeImmutable $dateStart, DateTimeImmutable $dateEnd): int {
        return date_diff($dateStart, $dateEnd)->format("%a") ;
Адлан Шамавов's avatar
Адлан Шамавов committed
    }

Адлан Шамавов's avatar
Адлан Шамавов committed
    #[Route('/{startDate}/{endDate}', name: 'home')] // 01-01-2024
    public function home(string $startDate, string $endDate): Response
Адлан Шамавов's avatar
Адлан Шамавов committed
        $countDays = $this->diffDays(new DateTimeImmutable($startDate), new DateTimeImmutable($endDate));
        return $this->render('home.html.twig', ['count' => $countDays]);
Адлан Шамавов's avatar
Адлан Шамавов committed
    }
}