Skip to content

Fix missing second offset in DateTimeZone::getName() #11292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ PHP NEWS
. Fixed bug GH-11222 (foreach by-ref may jump over keys during a rehash).
(Bob)

- Date:
. Fixed bug GH-11281 (DateTimeZone::getName() does not include seconds).
(ilutov)

- Exif:
. Fixed bug GH-10834 (exif_read_data() cannot read smaller stream wrapper
chunk sizes). (nielsdos)
Expand Down
16 changes: 12 additions & 4 deletions ext/date/php_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -1960,10 +1960,18 @@ static void php_timezone_to_string(php_timezone_obj *tzobj, zval *zv)
zend_string *tmpstr = zend_string_alloc(sizeof("UTC+05:00")-1, 0);
timelib_sll utc_offset = tzobj->tzi.utc_offset;

ZSTR_LEN(tmpstr) = snprintf(ZSTR_VAL(tmpstr), sizeof("+05:00"), "%c%02d:%02d",
utc_offset < 0 ? '-' : '+',
abs((int)(utc_offset / 3600)),
abs((int)(utc_offset % 3600) / 60));
if ((utc_offset % 60) == 0) {
ZSTR_LEN(tmpstr) = snprintf(ZSTR_VAL(tmpstr), sizeof("+05:00"), "%c%02d:%02d",
utc_offset < 0 ? '-' : '+',
abs((int)(utc_offset / 3600)),
abs((int)(utc_offset % 3600) / 60));
} else {
ZSTR_LEN(tmpstr) = snprintf(ZSTR_VAL(tmpstr), sizeof("+05:00:00"), "%c%02d:%02d:%02d",
utc_offset < 0 ? '-' : '+',
abs((int)(utc_offset / 3600)),
abs((int)(utc_offset % 3600) / 60),
abs((int)(utc_offset % 60)));
}

ZVAL_NEW_STR(zv, tmpstr);
}
Expand Down
2 changes: 1 addition & 1 deletion ext/date/tests/bug81097.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ object(DateTimeZone)#%d (%d) {
["timezone_type"]=>
int(1)
["timezone"]=>
string(6) "+01:45"
string(9) "+01:45:30"
}
2 changes: 1 addition & 1 deletion ext/date/tests/bug81565.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ DateTime::__set_state(array(
'timezone_type' => 1,
'timezone' => '+00:49',
))
+01:45
+01:45:30
9 changes: 9 additions & 0 deletions ext/date/tests/gh11281.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
--TEST--
Bug GH-11281 (DateTimeZone::getName() does not include seconds)
--FILE--
<?php
$tz = new DateTimeZone('+03:00:01');
echo $tz->getName();
?>
--EXPECT--
+03:00:01