Commit ab513098 authored by Nikita Chernykh's avatar Nikita Chernykh
Browse files

Merge branch 'PTPS_Function_6' into 'main'

Ptps function 6

See merge request !6
parents d785a12f cccfa9c6
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -82,5 +82,17 @@
            print $e->getMessage();
        }
    ?>

    <h1>Function 6</h1>
    <?php
        print "<h2>Пятницы 13: </h2>";
        try {
            foreach ($func->countFriday13(2024) as $date) {
                print $date->format("Y-m-d l") . "\n";
            }
        } catch (Exception $e) {
            print $e->getMessage();
        }
    ?>
</body>
</html>
 No newline at end of file
+18 −0
Original line number Diff line number Diff line
@@ -151,5 +151,23 @@ class Functions
        $dateInterval = date_diff(new DateTimeImmutable($endYear), $date);
        return (int)$dateInterval->format("%a") + 1;
    }

    /**
     * Вернет все пятницы 13 в году
     * @param int $year год, в котором необходимо произвести расчет
     * @return DateTimeImmutable[]
     * @throws Exception
     */

    public function countFriday13(int $year): iterable
    {
        $startDate = new DateTime("$year-01-01 Friday");
        ++$year;
        $endDate = new DateTime("$year-01-01");
        $interval = new DateInterval('P7D');
        foreach (new DatePeriod($startDate, $interval, $endDate) as $day) {
            yield new DateTimeImmutable($day->format("Y-m-d"));
        }
    }
}