@@ -1957,13 +1957,25 @@ static void php_timezone_to_string(php_timezone_obj *tzobj, zval *zv)
1957
1957
ZVAL_STRING (zv , tzobj -> tzi .tz -> name );
1958
1958
break ;
1959
1959
case TIMELIB_ZONETYPE_OFFSET : {
1960
- zend_string * tmpstr = zend_string_alloc (sizeof ("UTC+05:00" )- 1 , 0 );
1961
1960
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 );
1962
1972
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 ,
1964
1975
utc_offset < 0 ? '-' : '+' ,
1965
1976
abs ((int )(utc_offset / 3600 )),
1966
- abs ((int )(utc_offset % 3600 ) / 60 ));
1977
+ abs ((int )(utc_offset % 3600 ) / 60 ),
1978
+ abs (seconds ));
1967
1979
1968
1980
ZVAL_NEW_STR (zv , tmpstr );
1969
1981
}
0 commit comments