@@ -1957,13 +1957,25 @@ static void php_timezone_to_string(php_timezone_obj *tzobj, zval *zv)
19571957 ZVAL_STRING (zv , tzobj -> tzi .tz -> name );
19581958 break ;
19591959 case TIMELIB_ZONETYPE_OFFSET : {
1960- zend_string * tmpstr = zend_string_alloc (sizeof ("UTC+05:00" )- 1 , 0 );
19611960 timelib_sll utc_offset = tzobj -> tzi .utc_offset ;
1961+ int seconds = utc_offset % 60 ;
1962+ size_t size ;
1963+ const char * format ;
1964+ if (seconds == 0 ) {
1965+ size = sizeof ("+05:00" );
1966+ format = "%c%02d:%02d" ;
1967+ } else {
1968+ size = sizeof ("+05:00:01" );
1969+ format = "%c%02d:%02d:%02d" ;
1970+ }
1971+ zend_string * tmpstr = zend_string_alloc (size - 1 , 0 );
19621972
1963- ZSTR_LEN (tmpstr ) = snprintf (ZSTR_VAL (tmpstr ), sizeof ("+05:00" ), "%c%02d:%02d" ,
1973+ /* Note: if seconds == 0, the seconds argument will be excessive and therefore ignored. */
1974+ ZSTR_LEN (tmpstr ) = snprintf (ZSTR_VAL (tmpstr ), size , format ,
19641975 utc_offset < 0 ? '-' : '+' ,
19651976 abs ((int )(utc_offset / 3600 )),
1966- abs ((int )(utc_offset % 3600 ) / 60 ));
1977+ abs ((int )(utc_offset % 3600 ) / 60 ),
1978+ abs (seconds ));
19671979
19681980 ZVAL_NEW_STR (zv , tmpstr );
19691981 }
0 commit comments