Loading index.php +12 −1 Original line number Diff line number Diff line Loading @@ -71,5 +71,16 @@ ]; print_r($func->prepareMenu($aMenu)); ?> <h1>Function 5</h1> <?php print "<h2>До НГ: </h2>"; try { print $func->howDaysToNy(new DateTimeImmutable()); } catch (Exception $e) { print $e->getMessage(); } ?> </body> </html> No newline at end of file src/Functions.php +14 −0 Original line number Diff line number Diff line Loading @@ -137,5 +137,19 @@ class Functions * ['name' => 'Посуда','depth' => 1,],]], * ]; */ /** * Функция рассчитывает кол-во дней до нового года * @param DateTimeImmutable $date дата от которой, необходимо рассчитать кол-во дней * @return int * @throws Exception */ public function howDaysToNy(DateTimeImmutable $date): int { $endYear = date("Y-12-31", date_timestamp_get($date)); $dateInterval = date_diff(new DateTimeImmutable($endYear), $date); return (int)$dateInterval->format("%a") + 1; } } Loading
index.php +12 −1 Original line number Diff line number Diff line Loading @@ -71,5 +71,16 @@ ]; print_r($func->prepareMenu($aMenu)); ?> <h1>Function 5</h1> <?php print "<h2>До НГ: </h2>"; try { print $func->howDaysToNy(new DateTimeImmutable()); } catch (Exception $e) { print $e->getMessage(); } ?> </body> </html> No newline at end of file
src/Functions.php +14 −0 Original line number Diff line number Diff line Loading @@ -137,5 +137,19 @@ class Functions * ['name' => 'Посуда','depth' => 1,],]], * ]; */ /** * Функция рассчитывает кол-во дней до нового года * @param DateTimeImmutable $date дата от которой, необходимо рассчитать кол-во дней * @return int * @throws Exception */ public function howDaysToNy(DateTimeImmutable $date): int { $endYear = date("Y-12-31", date_timestamp_get($date)); $dateInterval = date_diff(new DateTimeImmutable($endYear), $date); return (int)$dateInterval->format("%a") + 1; } }