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
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -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
+14 −0
Original line number Diff line number Diff line
@@ -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;
    }
}