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

add diffDays

parent 2bbcd697
Loading
Loading
Loading
Loading
+9 −15
Original line number Diff line number Diff line
<?php
/** 
 * Вернет все пятницы 13 в году 
 * @param int $yaer год, в котором необходимо произвести расчет 
 * @return DateTimeImmutable[]  
 * Вернет кол-во дней между датами 
 * @param DateTimeImmutable $dateStart дата начала
 * @param DateTimeImmutable $dateEnd дата окончания
 * @return int
 */
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"));
    }
function diffDays(DateTimeImmutable $dateStart, DateTimeImmutable $dateEnd): int {
    $dateInterval = date_diff($dateStart, $dateEnd);
    return $dateInterval->format("%a") ;
}

?>
@@ -25,9 +21,7 @@ function countFriday13(int $year): iterable {
</head>
<body>
    <?php
        foreach(countFriday13(2024) as $date) {
            print($date->format("Y-m-d l") . "\n");
        }
        print(diffDays(new DateTimeImmutable(), new DateTimeImmutable("2025-01-01")));
    ?>
</body>
</html>
 No newline at end of file