derick          Fri May  2 12:49:16 2008 UTC

  Modified files:              (Branch: PHP_5_3)
    /php-src/ext/date   php_date.c php_date.h 
    /php-src/ext/date/lib       tm2unixtime.c 
  Log:
  - MFH: Added DateInterval::createFromDateString() that creates an interval
    from the relative parts of a date/time string.
  - MFH: Fixed an issue where special relative bits were not applied.
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/date/php_date.c?r1=1.43.2.45.2.51.2.33&r2=1.43.2.45.2.51.2.34&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.33 
php-src/ext/date/php_date.c:1.43.2.45.2.51.2.34
--- php-src/ext/date/php_date.c:1.43.2.45.2.51.2.33     Thu May  1 16:15:26 2008
+++ php-src/ext/date/php_date.c Fri May  2 12:49:16 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_date.c,v 1.43.2.45.2.51.2.33 2008/05/01 16:15:26 derick Exp $ */
+/* $Id: php_date.c,v 1.43.2.45.2.51.2.34 2008/05/02 12:49:16 derick Exp $ */
 
 #include "php.h"
 #include "php_streams.h"
@@ -196,6 +196,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 */
@@ -244,6 +245,7 @@
 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}
 };
 
@@ -1629,6 +1631,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;
@@ -1636,7 +1639,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);
@@ -2246,8 +2251,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)
 {
@@ -3254,7 +3259,7 @@
        timelib_rel_time *reltime;
        
        php_set_error_handling(EH_THROW, NULL TSRMLS_CC);
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", 
&interval_string, &interval_string_length) == SUCCESS) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", 
&interval_string, &interval_string_length) == SUCCESS) {
                if (date_interval_initialize(&reltime, interval_string, 
interval_string_length TSRMLS_CC) == SUCCESS) {
                        diobj = zend_object_store_get_object(getThis() 
TSRMLS_CC);
                        diobj->diff = reltime;
@@ -3267,6 +3272,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.17.2.11.2.3.2.7&r2=1.17.2.11.2.3.2.8&diff_format=u
Index: php-src/ext/date/php_date.h
diff -u php-src/ext/date/php_date.h:1.17.2.11.2.3.2.7 
php-src/ext/date/php_date.h:1.17.2.11.2.3.2.8
--- php-src/ext/date/php_date.h:1.17.2.11.2.3.2.7       Thu May  1 00:12:24 2008
+++ php-src/ext/date/php_date.h Fri May  2 12:49:16 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_date.h,v 1.17.2.11.2.3.2.7 2008/05/01 00:12:24 derick Exp $ */
+/* $Id: php_date.h,v 1.17.2.11.2.3.2.8 2008/05/02 12:49:16 derick Exp $ */
 
 #ifndef PHP_DATE_H
 #define PHP_DATE_H
@@ -81,6 +81,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/tm2unixtime.c?r1=1.13.2.3.2.2.2.6&r2=1.13.2.3.2.2.2.7&diff_format=u
Index: php-src/ext/date/lib/tm2unixtime.c
diff -u php-src/ext/date/lib/tm2unixtime.c:1.13.2.3.2.2.2.6 
php-src/ext/date/lib/tm2unixtime.c:1.13.2.3.2.2.2.7
--- php-src/ext/date/lib/tm2unixtime.c:1.13.2.3.2.2.2.6 Thu May  1 16:15:45 2008
+++ php-src/ext/date/lib/tm2unixtime.c  Fri May  2 12:49:16 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: tm2unixtime.c,v 1.13.2.3.2.2.2.6 2008/05/01 16:15:45 derick Exp $ */
+/* $Id: tm2unixtime.c,v 1.13.2.3.2.2.2.7 2008/05/02 12:49:16 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