Loading index.php +15 −9 Original line number Diff line number Diff line <?php /** * Функция рассчитывает кол-во дней до нового года * @param DateTime $date дата от которой, необходимо рассчитать кол-во дней * @return int * Вернет все пятницы 13 в году * @param int $yaer год, в котором необходимо произвести расчет * @return DateTimeImmutable[] */ function howDaysToNy(DateTimeImmutable $date): int { $endYear = date("Y-12-31", date_timestamp_get($date)); $dateInterval = date_diff(new DateTimeImmutable($endYear), $date); return $dateInterval->format("%a") + 1; 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")); } } ?> Loading @@ -21,7 +25,9 @@ function howDaysToNy(DateTimeImmutable $date): int { </head> <body> <?php print(howDaysToNy(new DateTimeImmutable())); foreach(countFriday13(2024) as $date) { print($date->format("Y-m-d l") . "\n"); } ?> </body> </html> No newline at end of file Loading
index.php +15 −9 Original line number Diff line number Diff line <?php /** * Функция рассчитывает кол-во дней до нового года * @param DateTime $date дата от которой, необходимо рассчитать кол-во дней * @return int * Вернет все пятницы 13 в году * @param int $yaer год, в котором необходимо произвести расчет * @return DateTimeImmutable[] */ function howDaysToNy(DateTimeImmutable $date): int { $endYear = date("Y-12-31", date_timestamp_get($date)); $dateInterval = date_diff(new DateTimeImmutable($endYear), $date); return $dateInterval->format("%a") + 1; 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")); } } ?> Loading @@ -21,7 +25,9 @@ function howDaysToNy(DateTimeImmutable $date): int { </head> <body> <?php print(howDaysToNy(new DateTimeImmutable())); foreach(countFriday13(2024) as $date) { print($date->format("Y-m-d l") . "\n"); } ?> </body> </html> No newline at end of file