Commit 36458228 authored by Адлан Шамавов's avatar Адлан Шамавов
Browse files

add diffDays

parent 84bd1fab
Loading
Loading
Loading
Loading
+6 −16
Original line number Diff line number Diff line
@@ -12,24 +12,14 @@ 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"));
    private function diffDays(DateTimeImmutable $dateStart, DateTimeImmutable $dateEnd): int {
        return date_diff($dateStart, $dateEnd)->format("%a") ;
    }
    }


    #[Route('/{year}', name: 'home')]
    public function home(int $year): Response
    #[Route('/{startDate}/{endDate}', name: 'home')] // 01-01-2024
    public function home(string $startDate, string $endDate): Response
    {
        $fridays = array();
        foreach($this->countFriday13($year) as $date) {
            $fridays[] = $date->format("Y-m-d l");
        }
        return $this->render('home.html.twig', ['fridays' => $fridays]);
        $countDays = $this->diffDays(new DateTimeImmutable($startDate), new DateTimeImmutable($endDate));
        return $this->render('home.html.twig', ['count' => $countDays]);
    }
}
+1 −4
Original line number Diff line number Diff line
{% block body %}
    <h1>Кол-во пятниц 13 в году: {{ fridays|length }}</h1>
    {% for day in fridays %}
        <p>{{ day }}</p>
    {% endfor %}
    <h1>Кол-во дней между датами: {{ count }}</h1>
{% endblock %}
 No newline at end of file