diff options
author | Derick Rethans <derick@php.net> | 2008-01-28 21:12:41 +0000 |
---|---|---|
committer | Derick Rethans <derick@php.net> | 2008-01-28 21:12:41 +0000 |
commit | a1180690a4535175ed2e69899b209fc15377376a (patch) | |
tree | 47f951a1ce268b8ad0160dab05c7c905947f53f5 | |
parent | afd01152f4b53c90f57d91a6f9e670a2053557b9 (diff) | |
download | php-git-a1180690a4535175ed2e69899b209fc15377376a.tar.gz |
- MFH: Added two optional parameters to timezone_transitions_get() /
DateTimeZone::getTranstions() to limit the range of transitions being
returned.
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | ext/date/php_date.c | 42 |
2 files changed, 32 insertions, 13 deletions
@@ -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) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 4ad2f08efc..ef54df75b0 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -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, ×tamp_begin, ×tamp_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; + } } } /* }}} */ |