derick          Sun May  4 09:59:42 2008 UTC

  Modified files:              
    /php-src/ext/date   php_date.c 
    /php-src/ext/date/lib       parse_iso_intervals.c parse_iso_intervals.re 
  Log:
  - Added support for using ISO 8601 time intervals to define a DatePeriod
    iterator.
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/date/php_date.c?r1=1.184&r2=1.185&diff_format=u
Index: php-src/ext/date/php_date.c
diff -u php-src/ext/date/php_date.c:1.184 php-src/ext/date/php_date.c:1.185
--- php-src/ext/date/php_date.c:1.184   Sat May  3 10:59:14 2008
+++ php-src/ext/date/php_date.c Sun May  4 09:59:42 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_date.c,v 1.184 2008/05/03 10:59:14 derick Exp $ */
+/* $Id: php_date.c,v 1.185 2008/05/04 09:59:42 derick Exp $ */
 
 #include "php.h"
 #include "php_streams.h"
@@ -3538,6 +3538,30 @@
 }
 /* }}} */
 
+static int date_period_initialize(timelib_time **st, timelib_time **et, 
timelib_rel_time **d, int *recurrences, /*const*/ char *format, int 
format_length TSRMLS_DC)
+{
+       timelib_time     *b = NULL, *e = NULL;
+       timelib_rel_time *p = NULL;
+       int               r = 0;
+       int               retval = 0;
+       struct timelib_error_container *errors;
+
+       timelib_strtointerval(format, format_length, &b, &e, &p, &r, &errors);
+       
+       if (errors->error_count > 0) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown or bad 
format (%s)", format);
+               retval = FAILURE;
+       } else {
+               *st = b;
+               *et = e;
+               *d  = p;
+               *recurrences = r;
+               retval = SUCCESS;
+       }
+       timelib_error_container_dtor(errors);
+       return retval;
+}
+
 /* {{{ proto DatePeriod::__construct(DateTime $start, DateInterval $interval, 
int recurrences|DateTime $end)
    Creates new DatePeriod object.
 */
@@ -3548,38 +3572,44 @@
        php_interval_obj *intobj;
        zval *start, *end = NULL, *interval;
        long  recurrences = 0, options = 0;
+       char *isostr = NULL;
+       int   isostr_len;
        timelib_time *clone;
        
        php_set_error_handling(EH_THROW, NULL TSRMLS_CC);
        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;
+                       if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, 
ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &isostr, &isostr_len, &options) == FAILURE) {
+                               php_error_docref(NULL TSRMLS_CC, E_WARNING, 
"This constructor accepts either (DateTime, DateInterval, int) OR (DateTime, 
DateInterval, DateTime) OR (string) as arguments.");
+                               return;
+                       }
                }
        }
 
-       /* 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) {
-               clone->tz_abbr = strdup(dateobj->time->tz_abbr);
-       }
-       if (dateobj->time->tz_info) {
-               clone->tz_info = timelib_tzinfo_clone(dateobj->time->tz_info);
-       }
-       dpobj->start = clone;
+       if (isostr_len) {
+               date_period_initialize(&(dpobj->start), &(dpobj->end), 
&(dpobj->interval), (int*) &recurrences, isostr, isostr_len TSRMLS_CC);
+               if (dpobj->start == NULL) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "The ISO 
interval '%s' did not contain a start date.", isostr);
+               }
+               if (dpobj->interval == NULL) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "The ISO 
interval '%s' did not contain an interval.", isostr);
+               }
+               if (dpobj->end == NULL && recurrences == 0) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "The ISO 
interval '%s' did not contain an end date or a recurrence count.", isostr);
+               }
 
-       /* interval */
-       dpobj->interval = timelib_rel_time_clone(intobj->diff);
+               timelib_update_ts(dpobj->start, NULL);
+               if (dpobj->end) {
+                       timelib_update_ts(dpobj->end, NULL);
+               }
+       } else {
+               /* init */
+               intobj  = (php_interval_obj *) 
zend_object_store_get_object(interval TSRMLS_CC);
 
-       /* end date */
-       if (end) {
-               dateobj = (php_date_obj *) zend_object_store_get_object(end 
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) {
@@ -3588,7 +3618,24 @@
                if (dateobj->time->tz_info) {
                        clone->tz_info = 
timelib_tzinfo_clone(dateobj->time->tz_info);
                }
-               dpobj->end = clone;
+               dpobj->start = clone;
+
+               /* interval */
+               dpobj->interval = timelib_rel_time_clone(intobj->diff);
+
+               /* 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 */
http://cvs.php.net/viewvc.cgi/php-src/ext/date/lib/parse_iso_intervals.c?r1=1.2&r2=1.3&diff_format=u
Index: php-src/ext/date/lib/parse_iso_intervals.c
diff -u php-src/ext/date/lib/parse_iso_intervals.c:1.2 
php-src/ext/date/lib/parse_iso_intervals.c:1.3
--- php-src/ext/date/lib/parse_iso_intervals.c:1.2      Fri Apr 25 12:55:16 2008
+++ php-src/ext/date/lib/parse_iso_intervals.c  Sun May  4 09:59:42 2008
@@ -1,4 +1,4 @@
-/* Generated by re2c 0.13.3 on Mon Apr  7 19:58:19 2008 */
+/* Generated by re2c 0.13.4 on Sun May  4 11:58:27 2008 */
 #line 1 "ext/date/lib/parse_iso_intervals.re"
 /*
    +----------------------------------------------------------------------+
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: parse_iso_intervals.c,v 1.2 2008/04/25 12:55:16 derick Exp $ */
+/* $Id: parse_iso_intervals.c,v 1.3 2008/05/04 09:59:42 derick Exp $ */
 
 #include "timelib.h"
 
@@ -325,10 +325,10 @@
        if ((YYLIMIT - YYCURSOR) < 20) YYFILL(20);
        yych = *YYCURSOR;
        if (yych <= ',') {
-               if (yych <= 0x0A) {
+               if (yych <= '\n') {
                        if (yych <= 0x00) goto yy9;
                        if (yych <= 0x08) goto yy11;
-                       if (yych <= 0x09) goto yy7;
+                       if (yych <= '\t') goto yy7;
                        goto yy9;
                } else {
                        if (yych == ' ') goto yy7;
@@ -527,7 +527,7 @@
 yy23:
        YYDEBUG(23, *YYCURSOR);
        ++YYCURSOR;
-       if (YYLIMIT == YYCURSOR) YYFILL(1);
+       if (YYLIMIT <= YYCURSOR) YYFILL(1);
        yych = *YYCURSOR;
        YYDEBUG(24, *YYCURSOR);
        if (yych <= '/') goto yy14;
@@ -830,7 +830,7 @@
 yy74:
        YYDEBUG(74, *YYCURSOR);
        ++YYCURSOR;
-       if (YYLIMIT == YYCURSOR) YYFILL(1);
+       if (YYLIMIT <= YYCURSOR) YYFILL(1);
        yych = *YYCURSOR;
        YYDEBUG(75, *YYCURSOR);
        if (yych <= '/') goto yy76;
@@ -905,11 +905,11 @@
        in.begin->h = TIMELIB_UNSET;
        in.begin->i = TIMELIB_UNSET;
        in.begin->s = TIMELIB_UNSET;
-       in.begin->f = TIMELIB_UNSET;
-       in.begin->z = TIMELIB_UNSET;
-       in.begin->dst = TIMELIB_UNSET;
+       in.begin->f = 0;
+       in.begin->z = 0;
+       in.begin->dst = 0;
        in.begin->is_localtime = 0;
-       in.begin->zone_type = 0;
+       in.begin->zone_type = TIMELIB_ZONETYPE_OFFSET;
 
        in.end = timelib_time_ctor();
        in.end->y = TIMELIB_UNSET;
@@ -918,11 +918,11 @@
        in.end->h = TIMELIB_UNSET;
        in.end->i = TIMELIB_UNSET;
        in.end->s = TIMELIB_UNSET;
-       in.end->f = TIMELIB_UNSET;
-       in.end->z = TIMELIB_UNSET;
-       in.end->dst = TIMELIB_UNSET;
+       in.end->f = 0;
+       in.end->z = 0;
+       in.end->dst = 0;
        in.end->is_localtime = 0;
-       in.end->zone_type = 0;
+       in.end->zone_type = TIMELIB_ZONETYPE_OFFSET;
 
        in.period = timelib_rel_time_ctor();
        in.period->y = 0;
http://cvs.php.net/viewvc.cgi/php-src/ext/date/lib/parse_iso_intervals.re?r1=1.2&r2=1.3&diff_format=u
Index: php-src/ext/date/lib/parse_iso_intervals.re
diff -u php-src/ext/date/lib/parse_iso_intervals.re:1.2 
php-src/ext/date/lib/parse_iso_intervals.re:1.3
--- php-src/ext/date/lib/parse_iso_intervals.re:1.2     Fri Apr 25 12:55:16 2008
+++ php-src/ext/date/lib/parse_iso_intervals.re Sun May  4 09:59:42 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: parse_iso_intervals.re,v 1.2 2008/04/25 12:55:16 derick Exp $ */
+/* $Id: parse_iso_intervals.re,v 1.3 2008/05/04 09:59:42 derick Exp $ */
 
 #include "timelib.h"
 
@@ -452,11 +452,11 @@
        in.begin->h = TIMELIB_UNSET;
        in.begin->i = TIMELIB_UNSET;
        in.begin->s = TIMELIB_UNSET;
-       in.begin->f = TIMELIB_UNSET;
-       in.begin->z = TIMELIB_UNSET;
-       in.begin->dst = TIMELIB_UNSET;
+       in.begin->f = 0;
+       in.begin->z = 0;
+       in.begin->dst = 0;
        in.begin->is_localtime = 0;
-       in.begin->zone_type = 0;
+       in.begin->zone_type = TIMELIB_ZONETYPE_OFFSET;
 
        in.end = timelib_time_ctor();
        in.end->y = TIMELIB_UNSET;
@@ -465,11 +465,11 @@
        in.end->h = TIMELIB_UNSET;
        in.end->i = TIMELIB_UNSET;
        in.end->s = TIMELIB_UNSET;
-       in.end->f = TIMELIB_UNSET;
-       in.end->z = TIMELIB_UNSET;
-       in.end->dst = TIMELIB_UNSET;
+       in.end->f = 0;
+       in.end->z = 0;
+       in.end->dst = 0;
        in.end->is_localtime = 0;
-       in.end->zone_type = 0;
+       in.end->zone_type = TIMELIB_ZONETYPE_OFFSET;
 
        in.period = timelib_rel_time_ctor();
        in.period->y = 0;

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to