Skip to content

Request 45543 #448

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
17 changes: 12 additions & 5 deletions ext/date/php_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -3293,12 +3293,19 @@ static void php_date_timezone_set(zval *object, zval *timezone_object, zval *ret
dateobj = (php_date_obj *) zend_object_store_get_object(object TSRMLS_CC);
DATE_CHECK_INITIALIZED(dateobj->time, DateTime);
tzobj = (php_timezone_obj *) zend_object_store_get_object(timezone_object TSRMLS_CC);
if (tzobj->type != TIMELIB_ZONETYPE_ID) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can only do this for zones with ID for now");
return;

switch (tzobj->type) {
case TIMELIB_ZONETYPE_OFFSET:
dateobj->time->tz_info->type->offset = (int32_t)tzobj->tzi.utc_offset * (-60);
break;
case TIMELIB_ZONETYPE_ID:
timelib_set_timezone(dateobj->time, tzobj->tzi.tz);
timelib_unixtime2local(dateobj->time, dateobj->time->sse);
break;
default:
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can only do this for zones with offset or ID");
break;
}
timelib_set_timezone(dateobj->time, tzobj->tzi.tz);
timelib_unixtime2local(dateobj->time, dateobj->time->sse);
}

/* {{{ proto DateTime date_timezone_set(DateTime object, DateTimeZone object)
Expand Down
21 changes: 21 additions & 0 deletions ext/date/tests/bug45543.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
Test for bug #45543: DateTime::setTimezone can not set timezones without ID
--CREDITS--
Boro Sitnikovski <buritomath@yahoo.com>
--INI--
date.timezone = UTC
--FILE--
<?php
$d1 = new DateTime('2008-01-01 12:00:00 +02:00');
$d2 = new DateTime('2008-01-01 12:00:00 UTC');
echo $d1->format(DATE_ISO8601), PHP_EOL;
echo $d2->format(DATE_ISO8601), PHP_EOL;
$d2->setTimeZone($d1->getTimeZone());
echo $d1->format(DATE_ISO8601), PHP_EOL;
echo $d2->format(DATE_ISO8601), PHP_EOL;
?>
--EXPECT--
2008-01-01T12:00:00+0200
2008-01-01T12:00:00+0000
2008-01-01T12:00:00+0200
2008-01-01T12:00:00+0200