<?php namespace App\Controller; use DateInterval; use DatePeriod; use DateTime; use DateTimeImmutable; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; class HomeController extends AbstractController { private function countFriday13(int $year): iterable { $stardDate = new DateTime("{$year}-01-01 Friday"); $year += 1; $endDate = new DateTime("{$year}-01-01"); $interval = new DateInterval('P7D'); foreach(new DatePeriod($stardDate, $interval, $endDate) as $day) { yield new DateTimeImmutable($day->format("Y-m-d")); } } #[Route('/{year}', name: 'home')] public function home(int $year): Response { $fridays = array(); foreach($this->countFriday13($year) as $date) { $fridays[] = $date->format("Y-m-d l"); } return $this->render('home.html.twig', ['fridays' => $fridays]); } }