summaryrefslogtreecommitdiff
path: root/ext/date/php_date.c
diff options
context:
space:
mode:
authorDerick Rethans <derick@php.net>2010-08-30 15:32:09 +0000
committerDerick Rethans <derick@php.net>2010-08-30 15:32:09 +0000
commitbd184cc5720939be40a152140f359b51475f0b70 (patch)
treefa748359bebf994bb1a5e5b2d584f9f5d9e499ff /ext/date/php_date.c
parenta7057e4e49729f65f1ff3a0bd926d5c1bb9fa7bb (diff)
downloadphp-git-bd184cc5720939be40a152140f359b51475f0b70.tar.gz
- Fixed bug #52668 (Iterating over a dateperiod twice is broken).
Diffstat (limited to 'ext/date/php_date.c')
-rw-r--r--ext/date/php_date.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index 95927949b8..86629618f5 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -1822,7 +1822,7 @@ static int date_period_it_has_more(zend_object_iterator *iter TSRMLS_DC)
{
date_period_it *iterator = (date_period_it *)iter;
php_period_obj *object = iterator->object;
- timelib_time *it_time = object->start;
+ timelib_time *it_time = object->current;
/* apply modification if it's not the first iteration */
if (!object->include_start_date || iterator->current_index > 0) {
@@ -1834,7 +1834,7 @@ static int date_period_it_has_more(zend_object_iterator *iter TSRMLS_DC)
}
if (object->end) {
- return object->start->sse < object->end->sse ? SUCCESS : FAILURE;
+ return object->current->sse < object->end->sse ? SUCCESS : FAILURE;
} else {
return (iterator->current_index < object->recurrences) ? SUCCESS : FAILURE;
}
@@ -1847,7 +1847,7 @@ static void date_period_it_current_data(zend_object_iterator *iter, zval ***data
{
date_period_it *iterator = (date_period_it *)iter;
php_period_obj *object = iterator->object;
- timelib_time *it_time = object->start;
+ timelib_time *it_time = object->current;
php_date_obj *newdateobj;
/* Create new object */
@@ -1895,6 +1895,10 @@ static void date_period_it_rewind(zend_object_iterator *iter TSRMLS_DC)
date_period_it *iterator = (date_period_it *)iter;
iterator->current_index = 0;
+ if (iterator->object->current) {
+ timelib_time_dtor(iterator->object->current);
+ }
+ iterator->object->current = timelib_time_clone(iterator->object->start);
date_period_it_invalidate_current(iter TSRMLS_CC);
}
/* }}} */
@@ -2335,6 +2339,10 @@ static void date_object_free_storage_period(void *object TSRMLS_DC)
timelib_time_dtor(intern->start);
}
+ if (intern->current) {
+ timelib_time_dtor(intern->current);
+ }
+
if (intern->end) {
timelib_time_dtor(intern->end);
}
@@ -3713,6 +3721,7 @@ PHP_METHOD(DatePeriod, __construct)
}
dpobj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ dpobj->current = NULL;
if (isostr_len) {
date_period_initialize(&(dpobj->start), &(dpobj->end), &(dpobj->interval), (int*) &recurrences, isostr, isostr_len TSRMLS_CC);
@@ -3754,14 +3763,7 @@ PHP_METHOD(DatePeriod, __construct)
/* end date */
if (end) {
dateobj = (php_date_obj *) zend_object_store_get_object(end TSRMLS_CC);
- clone = timelib_time_ctor();
- memcpy(clone, dateobj->time, sizeof(timelib_time));
- if (dateobj->time->tz_abbr) {
- clone->tz_abbr = strdup(dateobj->time->tz_abbr);
- }
- if (dateobj->time->tz_info) {
- clone->tz_info = dateobj->time->tz_info;
- }
+ clone = timelib_time_clone(dateobj->time);
dpobj->end = clone;
}
}