derick          Fri May  2 12:48:19 2008 UTC

  Modified files:              
    /php-src/ext/date   php_date.c php_date.h 
    /php-src/ext/date/lib       parse_date.c parse_date.re tm2unixtime.c 
  Log:
  - Added DateInterval::createFromDateString() that creates an interval
    from the relative parts of a date/time string.
  - Fixed an issue where special relative bits were not applied.
  #- @DOC
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/date/php_date.c?r1=1.181&r2=1.182&diff_format=u
Index: php-src/ext/date/php_date.c
diff -u php-src/ext/date/php_date.c:1.181 php-src/ext/date/php_date.c:1.182
--- php-src/ext/date/php_date.c:1.181   Thu May  1 16:14:29 2008
+++ php-src/ext/date/php_date.c Fri May  2 12:48:19 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_date.c,v 1.181 2008/05/01 16:14:29 derick Exp $ */
+/* $Id: php_date.c,v 1.182 2008/05/02 12:48:19 derick Exp $ */
 
 #include "php.h"
 #include "php_streams.h"
@@ -198,6 +198,7 @@
        PHP_FE(timezone_identifiers_list, NULL)
        PHP_FE(timezone_abbreviations_list, NULL)
 
+       PHP_FE(date_interval_create_from_date_string, NULL)
        PHP_FE(date_interval_format, NULL)
 
        /* Options and Configuration */
@@ -242,10 +243,11 @@
        PHP_ME_MAPPING(listIdentifiers,   timezone_identifiers_list,   NULL, 
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
        {NULL, NULL, NULL}
 };
-  
+
 const zend_function_entry date_funcs_interval[] = {
        PHP_ME(DateInterval,              __construct,                 NULL, 
ZEND_ACC_CTOR|ZEND_ACC_PUBLIC)
        PHP_ME_MAPPING(format,            date_interval_format,        NULL, 0)
+       PHP_ME_MAPPING(createFromDateString, 
date_interval_create_from_date_string,     NULL, 
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
        {NULL, NULL, NULL}
 };
 
@@ -1755,6 +1757,7 @@
 
        /* 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;
@@ -1762,7 +1765,9 @@
                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->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->sse_uptodate = 0;
                timelib_update_ts(it_time, NULL);
                timelib_update_from_sse(it_time);
@@ -2378,8 +2383,8 @@
 }
 /* }}} */
 
-/* {{{ proto DateTime date_create(string format, string time[, DateTimeZone 
object])
-   Returns new DateTime object
+/* {{{ proto DateTime date_create_from_format(string format, string time[, 
DateTimeZone object])
+   Returns new DateTime object formatted according to the specified format
 */
 PHP_FUNCTION(date_create_from_format)
 {
@@ -2585,22 +2590,20 @@
                                break;
                }
        }
-       if (parsed_time->have_relative || parsed_time->have_weekday_relative || 
parsed_time->have_special_relative || parsed_time->relative.first_last_day_of) {
+       if (parsed_time->have_relative) {
                MAKE_STD_ZVAL(element);
                array_init(element);
-       }
-       if (parsed_time->have_relative) {
                add_ascii_assoc_long(element, "year",   
parsed_time->relative.y);
                add_ascii_assoc_long(element, "month",  
parsed_time->relative.m);
                add_ascii_assoc_long(element, "day",    
parsed_time->relative.d);
                add_ascii_assoc_long(element, "hour",   
parsed_time->relative.h);
                add_ascii_assoc_long(element, "minute", 
parsed_time->relative.i);
                add_ascii_assoc_long(element, "second", 
parsed_time->relative.s);
-               if (parsed_time->have_weekday_relative) {
+               if (parsed_time->relative.have_weekday_relative) {
                        add_ascii_assoc_long(element, "weekday", 
parsed_time->relative.weekday);
                }
-               if (parsed_time->have_special_relative && 
(parsed_time->special.type == TIMELIB_SPECIAL_WEEKDAY)) {
-                       add_ascii_assoc_long(element, "weekdays", 
parsed_time->special.amount);
+               if (parsed_time->relative.have_special_relative && 
(parsed_time->relative.special.type == TIMELIB_SPECIAL_WEEKDAY)) {
+                       add_ascii_assoc_long(element, "weekdays", 
parsed_time->relative.special.amount);
                }
                if (parsed_time->relative.first_last_day_of) {
                        add_ascii_assoc_bool(element, 
parsed_time->relative.first_last_day_of == 1 ? "first_day_of_month" : 
"last_day_of_month", 1);
@@ -3260,7 +3263,7 @@
 #define add_last() add(tzobj->tzi.tz->timecnt - 1, timestamp_begin)
 
        array_init(return_value);
-  
+
        if (timestamp_begin == LONG_MIN) {
                add_nominal();
                begin = 0;
@@ -3437,6 +3440,31 @@
 }
 /* }}} */
 
+/* {{{ proto DateInterval date_interval_create_from_date_string(string time)
+   Uses the normal date parsers and sets up a DateInterval from the relative 
parts of the parsed string
+*/
+PHP_FUNCTION(date_interval_create_from_date_string)
+{
+       char           *time_str = NULL;
+       int             time_str_len = 0;
+       timelib_time   *time;
+       timelib_error_container *err = NULL;
+       php_interval_obj *diobj;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &time_str, 
&time_str_len) == FAILURE) {
+               RETURN_FALSE;
+       }
+
+       date_instantiate(date_ce_interval, return_value TSRMLS_CC);
+
+       time = timelib_strtotime(time_str, time_str_len, &err, DATE_TIMEZONEDB);
+       diobj = (php_interval_obj *) zend_object_store_get_object(return_value 
TSRMLS_CC);
+       diobj->diff = timelib_rel_time_clone(&time->relative);
+       timelib_time_dtor(time);
+       timelib_error_container_dtor(err);
+}
+/* }}} */
+
 /* {{{ date_interval_format -  */
 static char *date_interval_format(char *format, int format_len, 
timelib_rel_time *t)
 {
http://cvs.php.net/viewvc.cgi/php-src/ext/date/php_date.h?r1=1.39&r2=1.40&diff_format=u
Index: php-src/ext/date/php_date.h
diff -u php-src/ext/date/php_date.h:1.39 php-src/ext/date/php_date.h:1.40
--- php-src/ext/date/php_date.h:1.39    Thu May  1 00:10:25 2008
+++ php-src/ext/date/php_date.h Fri May  2 12:48:19 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_date.h,v 1.39 2008/05/01 00:10:25 derick Exp $ */
+/* $Id: php_date.h,v 1.40 2008/05/02 12:48:19 derick Exp $ */
 
 #ifndef PHP_DATE_H
 #define PHP_DATE_H
@@ -85,6 +85,7 @@
 
 PHP_METHOD(DateInterval, __construct);
 PHP_FUNCTION(date_interval_format);
+PHP_FUNCTION(date_interval_create_from_date_string);
 
 PHP_METHOD(DatePeriod, __construct);
 
http://cvs.php.net/viewvc.cgi/php-src/ext/date/lib/parse_date.c?r1=1.86&r2=1.87&diff_format=u
Index: php-src/ext/date/lib/parse_date.c
diff -u php-src/ext/date/lib/parse_date.c:1.86 
php-src/ext/date/lib/parse_date.c:1.87
--- php-src/ext/date/lib/parse_date.c:1.86      Thu May  1 16:14:29 2008
+++ php-src/ext/date/lib/parse_date.c   Fri May  2 12:48:19 2008
@@ -1,4 +1,4 @@
-/* Generated by re2c 0.13.4 on Thu May  1 18:13:58 2008 */
+/* Generated by re2c 0.13.4 on Fri May  2 14:36:50 2008 */
 #line 1 "ext/date/lib/parse_date.re"
 /*
    +----------------------------------------------------------------------+
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: parse_date.c,v 1.86 2008/05/01 16:14:29 derick Exp $ */
+/* $Id: parse_date.c,v 1.87 2008/05/02 12:48:19 derick Exp $ */
 
 #include "timelib.h"
 
http://cvs.php.net/viewvc.cgi/php-src/ext/date/lib/parse_date.re?r1=1.77&r2=1.78&diff_format=u
Index: php-src/ext/date/lib/parse_date.re
diff -u php-src/ext/date/lib/parse_date.re:1.77 
php-src/ext/date/lib/parse_date.re:1.78
--- php-src/ext/date/lib/parse_date.re:1.77     Thu May  1 16:14:29 2008
+++ php-src/ext/date/lib/parse_date.re  Fri May  2 12:48:19 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: parse_date.re,v 1.77 2008/05/01 16:14:29 derick Exp $ */
+/* $Id: parse_date.re,v 1.78 2008/05/02 12:48:19 derick Exp $ */
 
 #include "timelib.h"
 
http://cvs.php.net/viewvc.cgi/php-src/ext/date/lib/tm2unixtime.c?r1=1.24&r2=1.25&diff_format=u
Index: php-src/ext/date/lib/tm2unixtime.c
diff -u php-src/ext/date/lib/tm2unixtime.c:1.24 
php-src/ext/date/lib/tm2unixtime.c:1.25
--- php-src/ext/date/lib/tm2unixtime.c:1.24     Thu May  1 16:14:29 2008
+++ php-src/ext/date/lib/tm2unixtime.c  Fri May  2 12:48:19 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: tm2unixtime.c,v 1.24 2008/05/01 16:14:29 derick Exp $ */
+/* $Id: tm2unixtime.c,v 1.25 2008/05/02 12:48:19 derick Exp $ */
 
 #include "timelib.h"
 
@@ -193,9 +193,6 @@
                        break;
        }
        do_normalize(time);
-
-       memset(&(time->relative), 0, sizeof(time->relative));
-       time->have_relative = 0;
 }
 
 static void do_adjust_special_weekday(timelib_time* time)

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

Reply via email to