derick          Thu Mar 20 19:43:36 2008 UTC

  Modified files:              (Branch: PHP_5_3)
    /php-src/ext/date   php_date.c 
  Log:
  - MFH: Fix the DateTimeZone::getTransitions() algorithm.
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/date/php_date.c?r1=1.43.2.45.2.51.2.27&r2=1.43.2.45.2.51.2.28&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.27 
php-src/ext/date/php_date.c:1.43.2.45.2.51.2.28
--- php-src/ext/date/php_date.c:1.43.2.45.2.51.2.27     Sun Mar 16 15:15:21 2008
+++ php-src/ext/date/php_date.c Thu Mar 20 19:43:36 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_date.c,v 1.43.2.45.2.51.2.27 2008/03/16 15:15:21 iliaa Exp $ */
+/* $Id: php_date.c,v 1.43.2.45.2.51.2.28 2008/03/20 19:43:36 derick Exp $ */
 
 #include "php.h"
 #include "php_streams.h"
@@ -2604,7 +2604,7 @@
 {
        zval                *object, *element;
        php_timezone_obj    *tzobj;
-       int                  i, first = 1;
+       int                  i, begin = 0, found;
        long                 timestamp_begin = LONG_MIN, timestamp_end = 
LONG_MAX;
 
        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), 
"O|ll", &object, date_ce_timezone, &timestamp_begin, &timestamp_end) == 
FAILURE) {
@@ -2616,31 +2616,64 @@
                RETURN_FALSE;
        }
 
+#define add_nominal() \
+               MAKE_STD_ZVAL(element); \
+               array_init(element); \
+               add_assoc_long(element, "ts",     timestamp_begin); \
+               add_assoc_string(element, "time", 
php_format_date(DATE_FORMAT_ISO8601, 13, timestamp_begin, 0 TSRMLS_CC), 0); \
+               add_assoc_long(element, "offset", 
tzobj->tzi.tz->type[0].offset); \
+               add_assoc_bool(element, "isdst",  
tzobj->tzi.tz->type[0].isdst); \
+               add_assoc_string(element, "abbr", 
&tzobj->tzi.tz->timezone_abbr[tzobj->tzi.tz->type[0].abbr_idx], 1); \
+               add_next_index_zval(return_value, element);
+
+#define add(i,ts) \
+               MAKE_STD_ZVAL(element); \
+               array_init(element); \
+               add_assoc_long(element, "ts",     ts); \
+               add_assoc_string(element, "time", 
php_format_date(DATE_FORMAT_ISO8601, 13, ts, 0 TSRMLS_CC), 0); \
+               add_assoc_long(element, "offset", 
tzobj->tzi.tz->type[tzobj->tzi.tz->trans_idx[i]].offset); \
+               add_assoc_bool(element, "isdst",  
tzobj->tzi.tz->type[tzobj->tzi.tz->trans_idx[i]].isdst); \
+               add_assoc_string(element, "abbr", 
&tzobj->tzi.tz->timezone_abbr[tzobj->tzi.tz->type[tzobj->tzi.tz->trans_idx[i]].abbr_idx],
 1); \
+               add_next_index_zval(return_value, element);
+
+#define add_last() add(tzobj->tzi.tz->timecnt - 1, timestamp_begin)
+
        array_init(return_value);
-       for (i = 0; i < tzobj->tzi.tz->timecnt; ++i) {
-               if (tzobj->tzi.tz->trans[i] >= timestamp_begin && 
tzobj->tzi.tz->trans[i] < timestamp_end) {
-                       if (first && timestamp_begin != LONG_MIN && i > 0 && 
timestamp_begin != tzobj->tzi.tz->trans[i])
-                       {
-                               MAKE_STD_ZVAL(element);
-                               array_init(element);
-                               add_assoc_long(element, "ts",     
timestamp_begin);
-                               add_assoc_string(element, "time", 
php_format_date(DATE_FORMAT_ISO8601, 13, timestamp_begin, 0 TSRMLS_CC), 0);
-                               add_assoc_long(element, "offset", 
tzobj->tzi.tz->type[tzobj->tzi.tz->trans_idx[i-1]].offset);
-                               add_assoc_bool(element, "isdst",  
tzobj->tzi.tz->type[tzobj->tzi.tz->trans_idx[i-1]].isdst);
-                               add_assoc_string(element, "abbr", 
&tzobj->tzi.tz->timezone_abbr[tzobj->tzi.tz->type[tzobj->tzi.tz->trans_idx[i-1]].abbr_idx],
 1);
 
-                               add_next_index_zval(return_value, element);
-                       }
-                       MAKE_STD_ZVAL(element);
-                       array_init(element);
-                       add_assoc_long(element, "ts",     
tzobj->tzi.tz->trans[i]);
-                       add_assoc_string(element, "time", 
php_format_date(DATE_FORMAT_ISO8601, 13, tzobj->tzi.tz->trans[i], 0 TSRMLS_CC), 
0);
-                       add_assoc_long(element, "offset", 
tzobj->tzi.tz->type[tzobj->tzi.tz->trans_idx[i]].offset);
-                       add_assoc_bool(element, "isdst",  
tzobj->tzi.tz->type[tzobj->tzi.tz->trans_idx[i]].isdst);
-                       add_assoc_string(element, "abbr", 
&tzobj->tzi.tz->timezone_abbr[tzobj->tzi.tz->type[tzobj->tzi.tz->trans_idx[i]].abbr_idx],
 1);
+       if (timestamp_begin == LONG_MIN) {
+               add_nominal();
+               begin = 0;
+               found = 1;
+       } else {
+               begin = 0;
+               found = 0;
+               if (tzobj->tzi.tz->timecnt > 0) {
+                       do {
+                               if (tzobj->tzi.tz->trans[begin] > 
timestamp_begin) {
+                                       if (begin > 0) {
+                                               add(begin - 1, timestamp_begin);
+                                       } else {
+                                               add_nominal();
+                                       }
+                                       found = 1;
+                                       break;
+                               }
+                               begin++;
+                       } while (begin < tzobj->tzi.tz->timecnt);
+               }
+       }
 
-                       add_next_index_zval(return_value, element);
-                       first = 0;
+       if (!found) {
+               if (tzobj->tzi.tz->timecnt > 0) {
+                       add_last();
+               } else {
+                       add_nominal();
+               }
+       } else {
+               for (i = begin; i < tzobj->tzi.tz->timecnt; ++i) {
+                       if (tzobj->tzi.tz->trans[i] < timestamp_end) {
+                               add(i, tzobj->tzi.tz->trans[i]);
+                       }
                }
        }
 }



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

Reply via email to