Skip to content

Commit 56b77ac

Browse files
committed
Fix missing second offset in DateTimeZone::getName()
Fixes phpgh-11281
1 parent 93fa961 commit 56b77ac

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ PHP NEWS
1010
. Fixed bug GH-11222 (foreach by-ref may jump over keys during a rehash).
1111
(Bob)
1212

13+
- Date:
14+
. Fixed bug GH-11281 (DateTimeZone::getName() does not include seconds).
15+
(ilutov)
16+
1317
- Exif:
1418
. Fixed bug GH-10834 (exif_read_data() cannot read smaller stream wrapper
1519
chunk sizes). (nielsdos)

ext/date/php_date.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,10 +1960,18 @@ static void php_timezone_to_string(php_timezone_obj *tzobj, zval *zv)
19601960
zend_string *tmpstr = zend_string_alloc(sizeof("UTC+05:00")-1, 0);
19611961
timelib_sll utc_offset = tzobj->tzi.utc_offset;
19621962

1963-
ZSTR_LEN(tmpstr) = snprintf(ZSTR_VAL(tmpstr), sizeof("+05:00"), "%c%02d:%02d",
1964-
utc_offset < 0 ? '-' : '+',
1965-
abs((int)(utc_offset / 3600)),
1966-
abs((int)(utc_offset % 3600) / 60));
1963+
if ((utc_offset % 60) != 0) {
1964+
ZSTR_LEN(tmpstr) = snprintf(ZSTR_VAL(tmpstr), sizeof("+05:00:00"), "%c%02d:%02d:%02d",
1965+
utc_offset < 0 ? '-' : '+',
1966+
abs((int)(utc_offset / 3600)),
1967+
abs((int)(utc_offset % 3600) / 60),
1968+
abs((int)(utc_offset % 60)));
1969+
} else {
1970+
ZSTR_LEN(tmpstr) = snprintf(ZSTR_VAL(tmpstr), sizeof("+05:00"), "%c%02d:%02d",
1971+
utc_offset < 0 ? '-' : '+',
1972+
abs((int)(utc_offset / 3600)),
1973+
abs((int)(utc_offset % 3600) / 60));
1974+
}
19671975

19681976
ZVAL_NEW_STR(zv, tmpstr);
19691977
}

ext/date/tests/bug81097.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ object(DateTimeZone)#%d (%d) {
1010
["timezone_type"]=>
1111
int(1)
1212
["timezone"]=>
13-
string(6) "+01:45"
13+
string(9) "+01:45:30"
1414
}

ext/date/tests/bug81565.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ DateTime::__set_state(array(
1717
'timezone_type' => 1,
1818
'timezone' => '+00:49',
1919
))
20-
+01:45
20+
+01:45:30

ext/date/tests/gh11281.phpt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--TEST--
2+
Bug GH-11281 (DateTimeZone::getName() does not include seconds)
3+
--FILE--
4+
<?php
5+
$tz = new DateTimeZone('+03:00:01');
6+
echo $tz->getName();
7+
?>
8+
--EXPECT--
9+
+03:00:01

0 commit comments

Comments
 (0)