diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 0702f635230d4..bb5b9c1c3f082 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -1578,11 +1578,15 @@ static zend_result date_period_it_has_more(zend_object_iterator *iter) php_period_obj *object = Z_PHPPERIOD_P(&iterator->intern.data); if (object->end) { - if (object->include_end_date) { - return object->current->sse <= object->end->sse ? SUCCESS : FAILURE; - } else { - return object->current->sse < object->end->sse ? SUCCESS : FAILURE; + if (object->current->sse == object->end->sse) { + if (object->include_end_date) { + return object->current->us <= object->end->us ? SUCCESS : FAILURE; + } else { + return object->current->us < object->end->us ? SUCCESS : FAILURE; + } } + + return object->current->sse < object->end->sse ? SUCCESS : FAILURE; } else { return (iterator->current_index < object->recurrences) ? SUCCESS : FAILURE; } diff --git a/ext/date/tests/date_period_include_end.phpt b/ext/date/tests/date_period_include_end.phpt index c96e279465367..17a059e9dceb9 100644 --- a/ext/date/tests/date_period_include_end.phpt +++ b/ext/date/tests/date_period_include_end.phpt @@ -16,4 +16,3 @@ foreach (new DatePeriod($start, $interval, $end, DatePeriod::INCLUDE_END_DATE) a 2010-06-08 2010-06-09 2010-06-10 - diff --git a/ext/date/tests/date_period_microseconds.phpt b/ext/date/tests/date_period_microseconds.phpt new file mode 100644 index 0000000000000..e2329acc94ae5 --- /dev/null +++ b/ext/date/tests/date_period_microseconds.phpt @@ -0,0 +1,51 @@ +--TEST-- +DatePeriod: take microseconds into account +--FILE-- +format('Y-m-d H:i:s.u') . " to " . $end->format('Y-m-d H:i:s.u') . " (exclusive)\n"; +foreach (new DatePeriod($start, $interval, $end) as $day) { + echo $day->format('Y-m-d H:i:s.u') . "\n"; +} + +echo "from " . $start->format('Y-m-d H:i:s.u') . " to " . $end->format('Y-m-d H:i:s.u') . " (inclusive)\n"; +foreach (new DatePeriod($start, $interval, $end, DatePeriod::INCLUDE_END_DATE) as $day) { + echo $day->format('Y-m-d H:i:s.u') . "\n"; +} + +$end = new DateTime('2010-06-10T01:02:03.456790'); +echo "from " . $start->format('Y-m-d H:i:s.u') . " to " . $end->format('Y-m-d H:i:s.u') . " (exclusive)\n"; +foreach (new DatePeriod($start, $interval, $end) as $day) { + echo $day->format('Y-m-d H:i:s.u') . "\n"; +} + +$end = new DateTime('2010-06-10T01:02:03.456788'); +echo "from " . $start->format('Y-m-d H:i:s.u') . " to " . $end->format('Y-m-d H:i:s.u') . " (inclusive)\n"; +foreach (new DatePeriod($start, $interval, $end, DatePeriod::INCLUDE_END_DATE) as $day) { + echo $day->format('Y-m-d H:i:s.u') . "\n"; +} + +?> +--EXPECT-- +from 2010-06-07 01:02:03.456789 to 2010-06-10 01:02:03.456789 (exclusive) +2010-06-07 01:02:03.456789 +2010-06-08 01:02:03.456789 +2010-06-09 01:02:03.456789 +from 2010-06-07 01:02:03.456789 to 2010-06-10 01:02:03.456789 (inclusive) +2010-06-07 01:02:03.456789 +2010-06-08 01:02:03.456789 +2010-06-09 01:02:03.456789 +2010-06-10 01:02:03.456789 +from 2010-06-07 01:02:03.456789 to 2010-06-10 01:02:03.456790 (exclusive) +2010-06-07 01:02:03.456789 +2010-06-08 01:02:03.456789 +2010-06-09 01:02:03.456789 +2010-06-10 01:02:03.456789 +from 2010-06-07 01:02:03.456789 to 2010-06-10 01:02:03.456788 (inclusive) +2010-06-07 01:02:03.456789 +2010-06-08 01:02:03.456789 +2010-06-09 01:02:03.456789