]> granicus.if.org Git - php/commitdiff
- MFH: Added two optional parameters to timezone_transitions_get() /
authorDerick Rethans <derick@php.net>
Mon, 28 Jan 2008 21:12:41 +0000 (21:12 +0000)
committerDerick Rethans <derick@php.net>
Mon, 28 Jan 2008 21:12:41 +0000 (21:12 +0000)
  DateTimeZone::getTranstions() to limit the range of transitions being
  returned.

NEWS
ext/date/php_date.c

diff --git a/NEWS b/NEWS
index a529634ac1facf739b026c47a538ddf8fcc112c5..f08a2a8b286e94988be4985656d6fd4acae6e3aa 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -20,6 +20,9 @@ PHP                                                                        NEWS
     without invoking the date parser. (Scott)
   * date_timestamp_get() / DateTime::getTimestamp() to retrieve the Unix
     timestamp belonging to a date object.
+  * two optional parameters to timezone_transitions_get() /
+    DateTimeZone::getTranstions() to limit the range of transitions being
+    returned.
 
 - Added ability to store associative infor with objects in SplObjectStorage.
   (Marcus)
index 4ad2f08efc7a64a4604dbeee3daa4ef9b72b7764..ef54df75b03f12e5b40f2e697991fe89cc1cb43c 100644 (file)
@@ -2448,16 +2448,17 @@ PHP_FUNCTION(timezone_offset_get)
 }
 /* }}} */
 
-/* {{{ proto array timezone_transitions_get(DateTimeZone object)
-   Returns numeracilly indexed array containing associative array for all transitions for the timezone.
+/* {{{ proto array timezone_transitions_get(DateTimeZone object [, long timestamp_begin [, long timestamp_end ]])
+   Returns numerically indexed array containing associative array for all transitions in the specified range for the timezone.
 */
 PHP_FUNCTION(timezone_transitions_get)
 {
        zval                *object, *element;
        php_timezone_obj    *tzobj;
-       int                  i;
+       int                  i, first = 1;
+       long                 timestamp_begin = LONG_MIN, timestamp_end = LONG_MAX;
 
-       if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &object, date_ce_timezone) == FAILURE) {
+       if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|ll", &object, date_ce_timezone, &timestamp_begin, &timestamp_end) == FAILURE) {
                RETURN_FALSE;
        }
        tzobj = (php_timezone_obj *) zend_object_store_get_object(object TSRMLS_CC);
@@ -2468,15 +2469,30 @@ PHP_FUNCTION(timezone_transitions_get)
 
        array_init(return_value);
        for (i = 0; i < tzobj->tzi.tz->timecnt; ++i) {
-               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);
-
-               add_next_index_zval(return_value, element);
+               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);
+
+                       add_next_index_zval(return_value, element);
+                       first = 0;
+               }
        }
 }
 /* }}} */