summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerick Rethans <github@derickrethans.nl>2019-03-17 14:38:04 -0400
committerDerick Rethans <github@derickrethans.nl>2019-03-17 14:38:04 -0400
commit7e7ef44fab154e972a4677c579e73cb9ec175511 (patch)
treefa3c2c8ca48edb2d0bf073f5f21ac1a4af025a46
parent3a04b507ecb3d861f023172c713107198b19ce0b (diff)
parent1307275b431b3d15523237196a7e241709eceb95 (diff)
downloadphp-git-7e7ef44fab154e972a4677c579e73cb9ec175511.tar.gz
Merge branch 'PHP-7.2' into PHP-7.3
-rw-r--r--ext/date/php_date.c23
-rw-r--r--ext/date/php_date.h1
-rw-r--r--ext/date/tests/DatePeriod_getter.phpt16
3 files changed, 40 insertions, 0 deletions
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index f290730737..a8c38f15a6 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -551,6 +551,7 @@ static const zend_function_entry date_funcs_period[] = {
PHP_ME(DatePeriod, getStartDate, NULL, ZEND_ACC_PUBLIC)
PHP_ME(DatePeriod, getEndDate, NULL, ZEND_ACC_PUBLIC)
PHP_ME(DatePeriod, getDateInterval, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(DatePeriod, getRecurrences, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
@@ -4730,6 +4731,28 @@ PHP_METHOD(DatePeriod, getDateInterval)
}
/* }}} */
+/* {{{ proto int DatePeriod::getRecurrences()
+ Get recurrences.
+*/
+PHP_METHOD(DatePeriod, getRecurrences)
+{
+ php_period_obj *dpobj;
+ php_date_obj *dateobj;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ dpobj = Z_PHPPERIOD_P(ZEND_THIS);
+
+ if (0 == dpobj->recurrences - dpobj->include_start_date) {
+ return;
+ }
+
+ RETURN_LONG(dpobj->recurrences - dpobj->include_start_date);
+}
+/* }}} */
+
static int check_id_allowed(char *id, zend_long what) /* {{{ */
{
if (what & PHP_DATE_TIMEZONE_GROUP_AFRICA && strncasecmp(id, "Africa/", 7) == 0) return 1;
diff --git a/ext/date/php_date.h b/ext/date/php_date.h
index cb7c2931d8..691521dfa6 100644
--- a/ext/date/php_date.h
+++ b/ext/date/php_date.h
@@ -111,6 +111,7 @@ PHP_METHOD(DatePeriod, __set_state);
PHP_METHOD(DatePeriod, getStartDate);
PHP_METHOD(DatePeriod, getEndDate);
PHP_METHOD(DatePeriod, getDateInterval);
+PHP_METHOD(DatePeriod, getRecurrences);
/* Options and Configuration */
PHP_FUNCTION(date_default_timezone_set);
diff --git a/ext/date/tests/DatePeriod_getter.phpt b/ext/date/tests/DatePeriod_getter.phpt
index cd02bafd55..06fa031640 100644
--- a/ext/date/tests/DatePeriod_getter.phpt
+++ b/ext/date/tests/DatePeriod_getter.phpt
@@ -8,6 +8,7 @@ $start = new DateTime('2000-01-01 00:00:00', new DateTimeZone('Europe/Berlin'));
$end = new DateTime('2000-01-31 00:00:00', new DateTimeZone('UTC'));
$interval = new DateInterval('P1D');
$period = new DatePeriod($start, $interval, $end);
+$recurrences = 4;
var_dump($period->getStartDate()->format('Y-m-d H:i:s'));
var_dump($period->getStartDate()->getTimeZone()->getName());
@@ -16,6 +17,17 @@ var_dump($period->getEndDate()->format('Y-m-d H:i:s'));
var_dump($period->getEndDate()->getTimeZone()->getName());
var_dump($period->getDateInterval()->format('%R%y-%m-%d-%h-%i-%s'));
+var_dump($period->getRecurrences());
+
+$periodWithRecurrences = new DatePeriod($start, $interval, $recurrences);
+
+var_dump($periodWithRecurrences->getRecurrences());
+var_dump($periodWithRecurrences->getEndDate());
+
+$periodWithRecurrencesWithoutStart = new DatePeriod($start, $interval, $recurrences, DatePeriod::EXCLUDE_START_DATE);
+
+var_dump($periodWithRecurrences->getRecurrences());
+
?>
--EXPECT--
string(19) "2000-01-01 00:00:00"
@@ -23,3 +35,7 @@ string(13) "Europe/Berlin"
string(19) "2000-01-31 00:00:00"
string(3) "UTC"
string(12) "+0-0-1-0-0-0"
+NULL
+int(4)
+NULL
+int(4)