Commit 4555595f authored by Nikita Chernykh's avatar Nikita Chernykh
Browse files

Merge branch 'PTPS_Function_7' into 'main'

Ptps function 7

See merge request !7
parents ab513098 4d1bcb5b
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -94,5 +94,12 @@
            print $e->getMessage();
        }
    ?>


    <h1>Function 7</h1>
    <?php
        print "<h2>Разница дней: </h2>";
        print $func->diffDays(new DateTimeImmutable(), new DateTimeImmutable("2025-01-01"));
    ?>
</body>
</html>
 No newline at end of file
+12 −0
Original line number Diff line number Diff line
@@ -169,5 +169,17 @@ class Functions
            yield new DateTimeImmutable($day->format("Y-m-d"));
        }
    }

    /**
     * Вернет кол-во дней между датами
     * @param DateTimeImmutable $dateStart дата начала
     * @param DateTimeImmutable $dateEnd дата окончания
     * @return int
     */
    public function diffDays(DateTimeImmutable $dateStart, DateTimeImmutable $dateEnd): int
    {
        $dateInterval = date_diff($dateStart, $dateEnd);
        return (int)$dateInterval->format("%a") ;
    }
}