@@ -2024,13 +2024,25 @@ static void php_timezone_to_string(php_timezone_obj *tzobj, zval *zv)
20242024 ZVAL_STRING (zv , tzobj -> tzi .tz -> name );
20252025 break ;
20262026 case TIMELIB_ZONETYPE_OFFSET : {
2027- zend_string * tmpstr = zend_string_alloc (sizeof ("UTC+05:00" )- 1 , 0 );
20282027 timelib_sll utc_offset = tzobj -> tzi .utc_offset ;
2028+ int seconds = utc_offset % 60 ;
2029+ size_t size ;
2030+ const char * format ;
2031+ if (seconds == 0 ) {
2032+ size = sizeof ("+05:00" );
2033+ format = "%c%02d:%02d" ;
2034+ } else {
2035+ size = sizeof ("+05:00:01" );
2036+ format = "%c%02d:%02d:%02d" ;
2037+ }
2038+ zend_string * tmpstr = zend_string_alloc (size - 1 , 0 );
20292039
2030- ZSTR_LEN (tmpstr ) = snprintf (ZSTR_VAL (tmpstr ), sizeof ("+05:00" ), "%c%02d:%02d" ,
2040+ /* Note: if seconds == 0, the seconds argument will be excessive and therefore ignored. */
2041+ ZSTR_LEN (tmpstr ) = snprintf (ZSTR_VAL (tmpstr ), size , format ,
20312042 utc_offset < 0 ? '-' : '+' ,
20322043 abs ((int )(utc_offset / 3600 )),
2033- abs ((int )(utc_offset % 3600 ) / 60 ));
2044+ abs ((int )(utc_offset % 3600 ) / 60 ),
2045+ abs (seconds ));
20342046
20352047 ZVAL_NEW_STR (zv , tmpstr );
20362048 }
0 commit comments