Skip to content

Commit 0325e78

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
2 parents 33d4282 + 7e7ef44 commit 0325e78

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
@@ -547,6 +547,7 @@ static const zend_function_entry date_funcs_period[] = {
547547
PHP_ME(DatePeriod, getStartDate, NULL, ZEND_ACC_PUBLIC)
548548
PHP_ME(DatePeriod, getEndDate, NULL, ZEND_ACC_PUBLIC)
549549
PHP_ME(DatePeriod, getDateInterval, NULL, ZEND_ACC_PUBLIC)
550+
PHP_ME(DatePeriod, getRecurrences, NULL, ZEND_ACC_PUBLIC)
550551
PHP_FE_END
551552
};
552553

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

4733+
/* {{{ proto int DatePeriod::getRecurrences()
4734+
Get recurrences.
4735+
*/
4736+
PHP_METHOD(DatePeriod, getRecurrences)
4737+
{
4738+
php_period_obj *dpobj;
4739+
php_date_obj *dateobj;
4740+
4741+
if (zend_parse_parameters_none() == FAILURE) {
4742+
return;
4743+
}
4744+
4745+
dpobj = Z_PHPPERIOD_P(ZEND_THIS);
4746+
4747+
if (0 == dpobj->recurrences - dpobj->include_start_date) {
4748+
return;
4749+
}
4750+
4751+
RETURN_LONG(dpobj->recurrences - dpobj->include_start_date);
4752+
}
4753+
/* }}} */
4754+
47324755
static int check_id_allowed(char *id, zend_long what) /* {{{ */
47334756
{
47344757
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
@@ -107,6 +107,7 @@ PHP_METHOD(DatePeriod, __set_state);
107107
PHP_METHOD(DatePeriod, getStartDate);
108108
PHP_METHOD(DatePeriod, getEndDate);
109109
PHP_METHOD(DatePeriod, getDateInterval);
110+
PHP_METHOD(DatePeriod, getRecurrences);
110111

111112
/* Options and Configuration */
112113
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)