derick          Sat May  3 10:59:36 2008 UTC

  Modified files:              (Branch: PHP_5_3)
    /php-src    NEWS 
    /php-src/ext/date   php_date.c 
  Log:
  - Added support for using an end date to limit the amount of recursions
    with the DatePeriod iterator.
  #- @doc
  
  
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.965.2.169&r2=1.2027.2.547.2.965.2.170&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.965.2.169 
php-src/NEWS:1.2027.2.547.2.965.2.170
--- php-src/NEWS:1.2027.2.547.2.965.2.169       Sat May  3 10:04:36 2008
+++ php-src/NEWS        Sat May  3 10:59:36 2008
@@ -60,7 +60,8 @@
     phrases so that they actually mean the week and not a seven day period
     around the current day.
   . added the DatePeriod class, that supports iterating over a DateTime object
-    applying a DateInterval on each iteration.
+       applying a DateInterval on each iteration, up to an end date or limited 
by
+       a maximum number of occurences.
 
 - Added functionality to SPL extension:
   . Added SPL to list of standard extensions that cannot be disabled. (Marcus)
http://cvs.php.net/viewvc.cgi/php-src/ext/date/php_date.c?r1=1.43.2.45.2.51.2.35&r2=1.43.2.45.2.51.2.36&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.35 
php-src/ext/date/php_date.c:1.43.2.45.2.51.2.36
--- php-src/ext/date/php_date.c:1.43.2.45.2.51.2.35     Fri May  2 21:33:05 2008
+++ php-src/ext/date/php_date.c Sat May  3 10:59:36 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_date.c,v 1.43.2.45.2.51.2.35 2008/05/02 21:33:05 derick Exp $ */
+/* $Id: php_date.c,v 1.43.2.45.2.51.2.36 2008/05/03 10:59:36 derick Exp $ */
 
 #include "php.h"
 #include "php_streams.h"
@@ -1614,40 +1614,36 @@
 /* {{{ date_period_it_has_more */
 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;
-
-       return (iterator->current_index < object->recurrences) ? SUCCESS : 
FAILURE;
-}
-/* }}} */
-
-
-/* {{{ date_period_it_current_data */
-static void date_period_it_current_data(zend_object_iterator *iter, zval 
***data TSRMLS_DC)
-{
-       date_period_it   *iterator = (date_period_it *)iter;
-       php_period_obj   *object   = iterator->object;
-       timelib_time     *it_time = object->start;
-       php_date_obj     *newdateobj;
+       date_period_it *iterator = (date_period_it *)iter;
+       php_period_obj *object   = iterator->object;
+       timelib_time   *it_time = object->start;
 
        /* apply modification if it's not the first iteration */
        if (!object->include_start_date || iterator->current_index > 0) {
                it_time->have_relative = 1;
-               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->relative.special = object->interval->special;
-               it_time->relative.have_weekday_relative = 
object->interval->have_weekday_relative;
-               it_time->relative.have_special_relative = 
object->interval->have_special_relative;
+               it_time->relative = *object->interval;
                it_time->sse_uptodate = 0;
                timelib_update_ts(it_time, NULL);
                timelib_update_from_sse(it_time);
        }
 
+       if (object->end) {
+               return object->start->sse < object->end->sse ? SUCCESS : 
FAILURE;
+       } else {
+               return (iterator->current_index < object->recurrences) ? 
SUCCESS : FAILURE;
+       }
+}
+/* }}} */
+
+
+/* {{{ date_period_it_current_data */
+static void date_period_it_current_data(zend_object_iterator *iter, zval 
***data TSRMLS_DC)
+{
+       date_period_it *iterator = (date_period_it *)iter;
+       php_period_obj *object   = iterator->object;
+       timelib_time   *it_time = object->start;
+       php_date_obj   *newdateobj;
+
        /* Create new object */
        MAKE_STD_ZVAL(iterator->current);
        date_instantiate(date_ce_date, iterator->current TSRMLS_CC);
@@ -1669,7 +1665,7 @@
 /* {{{ date_period_it_current_key */
 static int date_period_it_current_key(zend_object_iterator *iter, char 
**str_key, uint *str_key_len, ulong *int_key TSRMLS_DC)
 {
-       date_period_it       *iterator = (date_period_it *)iter;
+       date_period_it   *iterator = (date_period_it *)iter;
        php_period_obj   *object   = iterator->object;
        *int_key = iterator->current_index;
        return HASH_KEY_IS_LONG;
@@ -1680,7 +1676,7 @@
 /* {{{ date_period_it_move_forward */
 static void date_period_it_move_forward(zend_object_iterator *iter TSRMLS_DC)
 {
-       date_period_it       *iterator = (date_period_it *)iter;
+       date_period_it   *iterator = (date_period_it *)iter;
        php_period_obj   *object   = iterator->object;
 
        iterator->current_index++;
@@ -1692,7 +1688,7 @@
 /* {{{ date_period_it_rewind */
 static void date_period_it_rewind(zend_object_iterator *iter TSRMLS_DC)
 {
-       date_period_it       *iterator = (date_period_it *)iter;
+       date_period_it   *iterator = (date_period_it *)iter;
        php_period_obj   *object   = iterator->object;
 
        iterator->current_index = 0;
@@ -3374,7 +3370,7 @@
 }
 /* }}} */
 
-/* {{{ proto DatePeriod::__construct(DateTime $start, DateInterval $interval, 
int recurrences)
+/* {{{ proto DatePeriod::__construct(DateTime $start, DateInterval $interval, 
int recurrences|DateTime $end)
    Creates new DatePeriod object.
 */
 PHP_METHOD(DatePeriod, __construct)
@@ -3382,18 +3378,24 @@
        php_period_obj   *dpobj;
        php_date_obj     *dateobj;
        php_interval_obj *intobj;
-       zval *start, *interval;
-       long  recurrences, options = 0;
+       zval *start, *end = NULL, *interval;
+       long  recurrences = 0, options = 0;
        timelib_time *clone;
        
        php_set_error_handling(EH_THROW, NULL TSRMLS_CC);
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OOl|l", &start, 
date_ce_date, &interval, date_ce_interval, &recurrences, &options) == FAILURE) {
-               RETURN_FALSE;
+       if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() 
TSRMLS_CC, "OOl|l", &start, date_ce_date, &interval, date_ce_interval, 
&recurrences, &options) == FAILURE) {
+               if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, 
ZEND_NUM_ARGS() TSRMLS_CC, "OOO|l", &start, date_ce_date, &interval, 
date_ce_interval, &end, date_ce_date, &options) == FAILURE) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "This 
constructor accepts either (DateTime, DateInterval, int) OR (DateTime, 
DateInterval, DateTime) as arguments.");
+                       return;
+               }
        }
 
-       dateobj = (php_date_obj *) zend_object_store_get_object(start 
TSRMLS_CC);
+       /* init */
        intobj  = (php_interval_obj *) zend_object_store_get_object(interval 
TSRMLS_CC);
+       dpobj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
+       /* start date */
+       dateobj = (php_date_obj *) zend_object_store_get_object(start 
TSRMLS_CC);
        clone = timelib_time_ctor();
        memcpy(clone, dateobj->time, sizeof(timelib_time));
        if (dateobj->time->tz_abbr) {
@@ -3402,14 +3404,32 @@
        if (dateobj->time->tz_info) {
                clone->tz_info = timelib_tzinfo_clone(dateobj->time->tz_info);
        }
+       dpobj->start = clone;
 
-       dpobj = zend_object_store_get_object(getThis() TSRMLS_CC);
+       /* interval */
        dpobj->interval = timelib_rel_time_clone(intobj->diff);
-       dpobj->start    = clone;
-       dpobj->initialized = 1;
+
+       /* 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 = 
timelib_tzinfo_clone(dateobj->time->tz_info);
+               }
+               dpobj->end = clone;
+       }
+
+       /* options */
        dpobj->include_start_date = !(options & 
PHP_DATE_PERIOD_EXCLUDE_START_DATE);
+
+       /* recurrrences */
        dpobj->recurrences = recurrences + dpobj->include_start_date;
 
+       dpobj->initialized = 1;
        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

Reply via email to