Skip to content

Commit e029019

Browse files
committed
Deduplicate code using php_timezone_to_string()
Looks like this usage was overlooked when the function was introduced.
1 parent ad52ec3 commit e029019

File tree

1 file changed

+23
-42
lines changed

1 file changed

+23
-42
lines changed

ext/date/php_date.c

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,48 +2358,6 @@ static zend_object *date_object_clone_timezone(zval *this_ptr) /* {{{ */
23582358
return &new_obj->std;
23592359
} /* }}} */
23602360

2361-
static HashTable *date_object_get_properties_timezone(zval *object) /* {{{ */
2362-
{
2363-
HashTable *props;
2364-
zval zv;
2365-
php_timezone_obj *tzobj;
2366-
2367-
2368-
tzobj = Z_PHPTIMEZONE_P(object);
2369-
2370-
props = zend_std_get_properties(object);
2371-
2372-
if (!tzobj->initialized) {
2373-
return props;
2374-
}
2375-
2376-
ZVAL_LONG(&zv, tzobj->type);
2377-
zend_hash_str_update(props, "timezone_type", sizeof("timezone_type")-1, &zv);
2378-
2379-
switch (tzobj->type) {
2380-
case TIMELIB_ZONETYPE_ID:
2381-
ZVAL_STRING(&zv, tzobj->tzi.tz->name);
2382-
break;
2383-
case TIMELIB_ZONETYPE_OFFSET: {
2384-
zend_string *tmpstr = zend_string_alloc(sizeof("UTC+05:00")-1, 0);
2385-
2386-
ZSTR_LEN(tmpstr) = snprintf(ZSTR_VAL(tmpstr), sizeof("+05:00"), "%c%02d:%02d",
2387-
tzobj->tzi.utc_offset < 0 ? '-' : '+',
2388-
abs(tzobj->tzi.utc_offset / 3600),
2389-
abs(((tzobj->tzi.utc_offset % 3600) / 60)));
2390-
2391-
ZVAL_NEW_STR(&zv, tmpstr);
2392-
}
2393-
break;
2394-
case TIMELIB_ZONETYPE_ABBR:
2395-
ZVAL_STRING(&zv, tzobj->tzi.z.abbr);
2396-
break;
2397-
}
2398-
zend_hash_str_update(props, "timezone", sizeof("timezone")-1, &zv);
2399-
2400-
return props;
2401-
} /* }}} */
2402-
24032361
static void php_timezone_to_string(php_timezone_obj *tzobj, zval *zv)
24042362
{
24052363
switch (tzobj->type) {
@@ -2424,6 +2382,29 @@ static void php_timezone_to_string(php_timezone_obj *tzobj, zval *zv)
24242382
}
24252383
}
24262384

2385+
static HashTable *date_object_get_properties_timezone(zval *object) /* {{{ */
2386+
{
2387+
HashTable *props;
2388+
zval zv;
2389+
php_timezone_obj *tzobj;
2390+
2391+
tzobj = Z_PHPTIMEZONE_P(object);
2392+
2393+
props = zend_std_get_properties(object);
2394+
2395+
if (!tzobj->initialized) {
2396+
return props;
2397+
}
2398+
2399+
ZVAL_LONG(&zv, tzobj->type);
2400+
zend_hash_str_update(props, "timezone_type", sizeof("timezone_type")-1, &zv);
2401+
2402+
php_timezone_to_string(tzobj, &zv);
2403+
zend_hash_str_update(props, "timezone", sizeof("timezone")-1, &zv);
2404+
2405+
return props;
2406+
} /* }}} */
2407+
24272408
static HashTable *date_object_get_debug_info_timezone(zval *object, int *is_temp) /* {{{ */
24282409
{
24292410
HashTable *ht, *props;

0 commit comments

Comments
 (0)