Skip to content

Commit 7e7ef44

Browse files
committed
Merge branch 'PHP-7.2' into PHP-7.3
2 parents 3a04b50 + 1307275 commit 7e7ef44

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

ext/date/php_date.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ static const zend_function_entry date_funcs_period[] = {
551551
PHP_ME(DatePeriod, getStartDate, NULL, ZEND_ACC_PUBLIC)
552552
PHP_ME(DatePeriod, getEndDate, NULL, ZEND_ACC_PUBLIC)
553553
PHP_ME(DatePeriod, getDateInterval, NULL, ZEND_ACC_PUBLIC)
554+
PHP_ME(DatePeriod, getRecurrences, NULL, ZEND_ACC_PUBLIC)
554555
PHP_FE_END
555556
};
556557

@@ -4730,6 +4731,28 @@ PHP_METHOD(DatePeriod, getDateInterval)
47304731
}
47314732
/* }}} */
47324733

4734+
/* {{{ proto int DatePeriod::getRecurrences()
4735+
Get recurrences.
4736+
*/
4737+
PHP_METHOD(DatePeriod, getRecurrences)
4738+
{
4739+
php_period_obj *dpobj;
4740+
php_date_obj *dateobj;
4741+
4742+
if (zend_parse_parameters_none() == FAILURE) {
4743+
return;
4744+
}
4745+
4746+
dpobj = Z_PHPPERIOD_P(ZEND_THIS);
4747+
4748+
if (0 == dpobj->recurrences - dpobj->include_start_date) {
4749+
return;
4750+
}
4751+
4752+
RETURN_LONG(dpobj->recurrences - dpobj->include_start_date);
4753+
}
4754+
/* }}} */
4755+
47334756
static int check_id_allowed(char *id, zend_long what) /* {{{ */
47344757
{
47354758
if (what & PHP_DATE_TIMEZONE_GROUP_AFRICA && strncasecmp(id, "Africa/", 7) == 0) return 1;

ext/date/php_date.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ PHP_METHOD(DatePeriod, __set_state);
111111
PHP_METHOD(DatePeriod, getStartDate);
112112
PHP_METHOD(DatePeriod, getEndDate);
113113
PHP_METHOD(DatePeriod, getDateInterval);
114+
PHP_METHOD(DatePeriod, getRecurrences);
114115

115116
/* Options and Configuration */
116117
PHP_FUNCTION(date_default_timezone_set);

ext/date/tests/DatePeriod_getter.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ $start = new DateTime('2000-01-01 00:00:00', new DateTimeZone('Europe/Berlin'));
88
$end = new DateTime('2000-01-31 00:00:00', new DateTimeZone('UTC'));
99
$interval = new DateInterval('P1D');
1010
$period = new DatePeriod($start, $interval, $end);
11+
$recurrences = 4;
1112

1213
var_dump($period->getStartDate()->format('Y-m-d H:i:s'));
1314
var_dump($period->getStartDate()->getTimeZone()->getName());
@@ -16,10 +17,25 @@ var_dump($period->getEndDate()->format('Y-m-d H:i:s'));
1617
var_dump($period->getEndDate()->getTimeZone()->getName());
1718

1819
var_dump($period->getDateInterval()->format('%R%y-%m-%d-%h-%i-%s'));
20+
var_dump($period->getRecurrences());
21+
22+
$periodWithRecurrences = new DatePeriod($start, $interval, $recurrences);
23+
24+
var_dump($periodWithRecurrences->getRecurrences());
25+
var_dump($periodWithRecurrences->getEndDate());
26+
27+
$periodWithRecurrencesWithoutStart = new DatePeriod($start, $interval, $recurrences, DatePeriod::EXCLUDE_START_DATE);
28+
29+
var_dump($periodWithRecurrences->getRecurrences());
30+
1931
?>
2032
--EXPECT--
2133
string(19) "2000-01-01 00:00:00"
2234
string(13) "Europe/Berlin"
2335
string(19) "2000-01-31 00:00:00"
2436
string(3) "UTC"
2537
string(12) "+0-0-1-0-0-0"
38+
NULL
39+
int(4)
40+
NULL
41+
int(4)

0 commit comments

Comments
 (0)