diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 96cd22129c1..7ac02bf733c 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -1430,6 +1430,7 @@ PHP_FUNCTION(getdate) #define PHP_DATE_TIMEZONE_PER_COUNTRY 0x1000 #define PHP_DATE_PERIOD_EXCLUDE_START_DATE 0x0001 +#define PHP_DATE_PERIOD_INCLUDE_END_DATE 0x0002 /* define an overloaded iterator structure */ @@ -1470,7 +1471,11 @@ static int date_period_it_has_more(zend_object_iterator *iter) php_period_obj *object = Z_PHPPERIOD_P(&iterator->intern.data); if (object->end) { - return object->current->sse < object->end->sse ? SUCCESS : FAILURE; + if (object->include_end_date) { + return object->current->sse <= object->end->sse ? SUCCESS : FAILURE; + } else { + return object->current->sse < object->end->sse ? SUCCESS : FAILURE; + } } else { return (iterator->current_index < object->recurrences) ? SUCCESS : FAILURE; } @@ -1734,6 +1739,7 @@ static void date_register_classes(void) /* {{{ */ zend_declare_class_constant_long(date_ce_period, const_name, sizeof(const_name)-1, value); REGISTER_PERIOD_CLASS_CONST_STRING("EXCLUDE_START_DATE", PHP_DATE_PERIOD_EXCLUDE_START_DATE); + REGISTER_PERIOD_CLASS_CONST_STRING("INCLUDE_END_DATE", PHP_DATE_PERIOD_INCLUDE_END_DATE); } /* }}} */ static zend_object *date_object_new_date(zend_class_entry *class_type) /* {{{ */ @@ -4567,9 +4573,10 @@ PHP_METHOD(DatePeriod, __construct) /* options */ dpobj->include_start_date = !(options & PHP_DATE_PERIOD_EXCLUDE_START_DATE); + dpobj->include_end_date = options & PHP_DATE_PERIOD_INCLUDE_END_DATE; /* recurrrences */ - dpobj->recurrences = recurrences + dpobj->include_start_date; + dpobj->recurrences = recurrences + dpobj->include_start_date + dpobj->include_end_date; dpobj->initialized = 1; } diff --git a/ext/date/php_date.h b/ext/date/php_date.h index d18529f10d3..aa6883a5e46 100644 --- a/ext/date/php_date.h +++ b/ext/date/php_date.h @@ -93,6 +93,7 @@ struct _php_period_obj { int recurrences; bool initialized; bool include_start_date; + int include_end_date; zend_object std; }; diff --git a/ext/date/tests/date_period_include_end.phpt b/ext/date/tests/date_period_include_end.phpt new file mode 100644 index 00000000000..c96e2794653 --- /dev/null +++ b/ext/date/tests/date_period_include_end.phpt @@ -0,0 +1,19 @@ +--TEST-- +DatePeriod::INCLUDE_END_DATE +--FILE-- +format('Y-m-d') . "\n"; +} +?> +--EXPECT-- +2010-06-07 +2010-06-08 +2010-06-09 +2010-06-10 +