Skip to content

DatePeriod not taking into account microseconds for end date #13773

Closed

Description

@mdkieran

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)

Activity

  1. self-assigned this
    on Mar 21, 2024
  2. derickr commented on Mar 21, 2024

    @derickr
    Member

    There is definitely a bug here, thanks for letting us know.

  3. added a commit that references this issue on Aug 21, 2024
    d6113ba
  4. dragoonis commented on Aug 21, 2024

    @dragoonis
    Contributor

    Well spotted, Matt! @mdkieran

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions