Loading index.php +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") ; } ?> Loading @@ -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 Loading
index.php +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") ; } ?> Loading @@ -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