Hey Arjen,
On 8 November 2016 at 09:32, Arjen Schol <ar...@parse.nl> wrote:
There is no easy way to set microseconds to 0, you have to call setTime
There actually is an easy way, you can pass microseconds absolute value
in the constructor as well, it would like: `new DateTime("5 minutes ago, 0
microseconds")`
As Dan said it is probably a mistkae in the code, really, and it is a very
popular one,
to think that `new DateTime("5 minutes ago") == new DateTime("5 minutes
ago")`.
If you sample it enough times even on pre-7 versions of PHP you will get
inequality as well: https://3v4l.org/JV59e (sorry for overloading 3v4l a
bit here).
It is especially an undesirable mistake because it causes failures
randomly,
no one likes their test suite failing /sometimes/, it makes debugging
a very unpleasant experience.
When doing date manipulations, let's say the task is to generate a report
for the
previous month, you need to always have a base date as a point of
reference:
```
$startDate = new DateTimeImmutable("first day of previous month,
00:00:00.0");
$endDate = $startDate->add(new DateInterval("P1M"));
```
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php