Skip to content
Snippets Groups Projects
CountFriday13Action.php 629 B
Newer Older
<?php

namespace App\Actions;

use DateTimeImmutable;

class CountFriday13Action
{
    /**
     * Вернет все пятницы 13 в году
     * @param int $year год, в котором необходимо произвести расчет
     * @return DateTimeImmutable[]
     */
    public function act(int $year): array
    {
        $AllFri13 = [];

        for ($i = 1; $i <= 12; $i++) {
            $next13 = (new DateTimeImmutable())->setDate($year, $i, 13);

            if ($next13->format("D") === "Fri") {
                $AllFri13[] = $next13;
            }
        }
        return $AllFri13;
    }
}