Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions ext/date/php_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion ext/date/tests/date_period_include_end.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ foreach (new DatePeriod($start, $interval, $end, DatePeriod::INCLUDE_END_DATE) a
2010-06-08
2010-06-09
2010-06-10

51 changes: 51 additions & 0 deletions ext/date/tests/date_period_microseconds.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
--TEST--
DatePeriod: take microseconds into account
--FILE--
<?php
date_default_timezone_set('UTC');
$start = new DateTime('2010-06-07T01:02:03.456789');
$end = new DateTime('2010-06-10T01:02:03.456789');
$interval = new DateInterval('P1D');

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";
}

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