@@ -2024,13 +2024,25 @@ static void php_timezone_to_string(php_timezone_obj *tzobj, zval *zv)
2024
2024
ZVAL_STRING (zv , tzobj -> tzi .tz -> name );
2025
2025
break ;
2026
2026
case TIMELIB_ZONETYPE_OFFSET : {
2027
- zend_string * tmpstr = zend_string_alloc (sizeof ("UTC+05:00" )- 1 , 0 );
2028
2027
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 );
2029
2039
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 ,
2031
2042
utc_offset < 0 ? '-' : '+' ,
2032
2043
abs ((int )(utc_offset / 3600 )),
2033
- abs ((int )(utc_offset % 3600 ) / 60 ));
2044
+ abs ((int )(utc_offset % 3600 ) / 60 ),
2045
+ abs (seconds ));
2034
2046
2035
2047
ZVAL_NEW_STR (zv , tmpstr );
2036
2048
}
0 commit comments