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

namespace App\Controller;

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
{
    private function howDaysToNy(DateTimeImmutable $date): int {
        $endYear = date("Y-12-31", date_timestamp_get($date));
        $dateInterval = date_diff(new DateTimeImmutable($endYear), $date);
        return $dateInterval->format("%a") + 1;
Адлан Шамавов's avatar
Адлан Шамавов committed
    }

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