Skip to content
Snippets Groups Projects
CountFriday13Repository.php 557 B
Newer Older
Akex's avatar
Akex committed
<?php

namespace App\Repository;
use DateTimeImmutable;

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

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

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