Skip to content
Snippets Groups Projects
Commit d785a12f authored by Nikita Chernykh's avatar Nikita Chernykh
Browse files

Merge branch 'PTPS_Function_5' into 'main'

Ptps function 5

See merge request !5
parents 33d65541 6cfdbf5a
No related branches found
No related tags found
1 merge request!5Ptps function 5
......@@ -70,6 +70,17 @@
['name' => 'Посуда','depth' => 1,],
];
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
......@@ -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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment