Skip to content

Commit 6eb83a6

Browse files
nyamsprodderickr
authored andcommitted
Fixed bug #75113: Added DatePeriod::getRecurrences() method.
1 parent f167b06 commit 6eb83a6

File tree

4 files changed

+46
-4
lines changed

4 files changed

+46
-4
lines changed

NEWS

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ PHP NEWS
1515
. Fixed bug #77742 (bcpow() implementation related to gcc compiler
1616
optimization). (Nikita)
1717

18-
- FPM:
19-
. Fixed bug #77677 (FPM fails to build on AIX due to missing WCOREDUMP).
20-
(Kevin Adler)
21-
2218
- Date:
2319
. Fixed bug #50020 (DateInterval:createDateFromString() silently fails).
2420
(Derick)
21+
. Fixed bug #75113 (Added DatePeriod::getRecurrences() method). (Ignace
22+
Nyamagana Butera)
23+
24+
- FPM:
25+
. Fixed bug #77677 (FPM fails to build on AIX due to missing WCOREDUMP).
26+
(Kevin Adler)
2527

2628
- GD:
2729
. Fixed bug #77700 (Writing truecolor images as GIF ignores interlace flag).

ext/date/php_date.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ const zend_function_entry date_funcs_period[] = {
543543
PHP_ME(DatePeriod, getStartDate, NULL, ZEND_ACC_PUBLIC)
544544
PHP_ME(DatePeriod, getEndDate, NULL, ZEND_ACC_PUBLIC)
545545
PHP_ME(DatePeriod, getDateInterval, NULL, ZEND_ACC_PUBLIC)
546+
PHP_ME(DatePeriod, getRecurrences, NULL, ZEND_ACC_PUBLIC)
546547
PHP_FE_END
547548
};
548549

@@ -4736,6 +4737,28 @@ PHP_METHOD(DatePeriod, getDateInterval)
47364737
}
47374738
/* }}} */
47384739

4740+
/* {{{ proto int DatePeriod::getRecurrences()
4741+
Get recurrences.
4742+
*/
4743+
PHP_METHOD(DatePeriod, getRecurrences)
4744+
{
4745+
php_period_obj *dpobj;
4746+
php_date_obj *dateobj;
4747+
4748+
if (zend_parse_parameters_none() == FAILURE) {
4749+
return;
4750+
}
4751+
4752+
dpobj = Z_PHPPERIOD_P(ZEND_THIS);
4753+
4754+
if (0 == dpobj->recurrences - dpobj->include_start_date) {
4755+
return;
4756+
}
4757+
4758+
RETURN_LONG(dpobj->recurrences - dpobj->include_start_date);
4759+
}
4760+
/* }}} */
4761+
47394762
static int check_id_allowed(char *id, zend_long what) /* {{{ */
47404763
{
47414764
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
@@ -112,6 +112,7 @@ PHP_METHOD(DatePeriod, __set_state);
112112
PHP_METHOD(DatePeriod, getStartDate);
113113
PHP_METHOD(DatePeriod, getEndDate);
114114
PHP_METHOD(DatePeriod, getDateInterval);
115+
PHP_METHOD(DatePeriod, getRecurrences);
115116

116117
/* Options and Configuration */
117118
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
--EXPECTF--
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)