derick Thu May 1 13:31:22 2008 UTC
Modified files: (Branch: PHP_5_3)
/php-src/ext/date php_date.c
Log:
- MFH: Include the starting date by default in the iterator output, but add an
option to disable this behavior.
http://cvs.php.net/viewvc.cgi/php-src/ext/date/php_date.c?r1=1.43.2.45.2.51.2.31&r2=1.43.2.45.2.51.2.32&diff_format=u
Index: php-src/ext/date/php_date.c
diff -u php-src/ext/date/php_date.c:1.43.2.45.2.51.2.31
php-src/ext/date/php_date.c:1.43.2.45.2.51.2.32
--- php-src/ext/date/php_date.c:1.43.2.45.2.51.2.31 Thu May 1 00:12:24 2008
+++ php-src/ext/date/php_date.c Thu May 1 13:31:22 2008
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_date.c,v 1.43.2.45.2.51.2.31 2008/05/01 00:12:24 derick Exp $ */
+/* $Id: php_date.c,v 1.43.2.45.2.51.2.32 2008/05/01 13:31:22 derick Exp $ */
#include "php.h"
#include "php_streams.h"
@@ -331,6 +331,7 @@
timelib_rel_time *interval;
int recurrences;
int initialized;
+ int include_start_date;
};
#define DATE_SET_CONTEXT \
@@ -1570,6 +1571,8 @@
#define PHP_DATE_TIMEZONE_GROUP_ALL 0x07FF
#define PHP_DATE_TIMEZONE_GROUP_ALL_W_BC 0x0FFF
+#define PHP_DATE_PERIOD_EXCLUDE_START_DATE 0x0001
+
/* define an overloaded iterator structure */
typedef struct {
@@ -1624,18 +1627,20 @@
timelib_time *it_time = object->start;
php_date_obj *newdateobj;
- /* apply modification */
- it_time->relative.y = object->interval->y;
- it_time->relative.m = object->interval->m;
- it_time->relative.d = object->interval->d;
- it_time->relative.h = object->interval->h;
- it_time->relative.i = object->interval->i;
- it_time->relative.s = object->interval->s;
- it_time->relative.weekday = object->interval->weekday;
- it_time->have_relative = 1;
- it_time->sse_uptodate = 0;
- timelib_update_ts(it_time, NULL);
- timelib_update_from_sse(it_time);
+ /* apply modification if it's not the first iteration */
+ if (!object->include_start_date || iterator->current_index > 0) {
+ it_time->relative.y = object->interval->y;
+ it_time->relative.m = object->interval->m;
+ it_time->relative.d = object->interval->d;
+ it_time->relative.h = object->interval->h;
+ it_time->relative.i = object->interval->i;
+ it_time->relative.s = object->interval->s;
+ it_time->relative.weekday = object->interval->weekday;
+ it_time->have_relative = 1;
+ it_time->sse_uptodate = 0;
+ timelib_update_ts(it_time, NULL);
+ timelib_update_from_sse(it_time);
+ }
/* Create new object */
MAKE_STD_ZVAL(iterator->current);
@@ -1789,6 +1794,11 @@
zend_class_implements(date_ce_period TSRMLS_CC, 1, zend_ce_traversable);
memcpy(&date_object_handlers_period, zend_get_std_object_handlers(),
sizeof(zend_object_handlers));
date_object_handlers_period.clone_obj = date_object_clone_period;
+
+#define REGISTER_PERIOD_CLASS_CONST_STRING(const_name, value) \
+ zend_declare_class_constant_long(date_ce_period, const_name,
sizeof(const_name)-1, value TSRMLS_CC);
+
+ REGISTER_PERIOD_CLASS_CONST_STRING("EXCLUDE_START_DATE",
PHP_DATE_PERIOD_EXCLUDE_START_DATE);
}
static inline zend_object_value date_object_new_date_ex(zend_class_entry
*class_type, php_date_obj **ptr TSRMLS_DC)
@@ -3346,11 +3356,11 @@
php_date_obj *dateobj;
php_interval_obj *intobj;
zval *start, *interval;
- long recurrences;
+ long recurrences, options = 0;
timelib_time *clone;
php_set_error_handling(EH_THROW, NULL TSRMLS_CC);
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OOl", &start,
date_ce_date, &interval, date_ce_interval, &recurrences) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OOl|l", &start,
date_ce_date, &interval, date_ce_interval, &recurrences, &options) == FAILURE) {
RETURN_FALSE;
}
@@ -3369,8 +3379,9 @@
dpobj = zend_object_store_get_object(getThis() TSRMLS_CC);
dpobj->interval = timelib_rel_time_clone(intobj->diff);
dpobj->start = clone;
- dpobj->recurrences = recurrences;
dpobj->initialized = 1;
+ dpobj->include_start_date = !(options &
PHP_DATE_PERIOD_EXCLUDE_START_DATE);
+ dpobj->recurrences = recurrences + dpobj->include_start_date;
php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
}
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php