mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
fixes #13773: DatePeriod does not take microseconds into account
This commit is contained in:
parent
69d9c12df6
commit
d6113ba8fe
3 changed files with 59 additions and 5 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
ext/date/tests/date_period_microseconds.phpt
Normal file
51
ext/date/tests/date_period_microseconds.phpt
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue