Closed
Description
Description
The following code:
$period = new DatePeriod(
new DateTime('2000-01-01 12:00:00'),
new DateInterval('P1D'),
new DateTime('2000-01-02 12:00:00.000001'),
);
foreach ($period as $date) {
echo $date->format('Y-m-d H:i:s') . '<br/>';
}
Resulted in this output:
2000-01-01 12:00:00
But I expected this output instead:
2000-01-01 12:00:00
2000-01-02 12:00:00
My understanding is that if you're going to yield a new date from the DatePeriod, as long as it's less than the end date, then it's allowed, otherwise you've reached the end. So whether the end date is 1 microsecond or 1 whole second greater than a would-be newly yielded date, it is still greater than it and ought be allowed.
The only information I could find about this was from this comment: https://php.vn.ua/manual/en/class.dateperiod.php#124147
PHP Version
PHP 8.2.15
Operating System
Fedora Linux 38 (Workstation Edition)