From bc85e31bdfb9ba1bc79ef0575021d5743b02ba7d Mon Sep 17 00:00:00 2001 From: Boro Sitnikovski Date: Fri, 13 Sep 2013 03:41:07 +0200 Subject: [PATCH] Bug 45543 Added handling for offset as well, besides ID. --- ext/date/php_date.c | 17 ++++++++++++----- ext/date/tests/bug45543.phpt | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 ext/date/tests/bug45543.phpt diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 7d3d1d739e113..e4a4ab7d810bf 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -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) diff --git a/ext/date/tests/bug45543.phpt b/ext/date/tests/bug45543.phpt new file mode 100644 index 0000000000000..4826c4161279e --- /dev/null +++ b/ext/date/tests/bug45543.phpt @@ -0,0 +1,21 @@ +--TEST-- +Test for bug #45543: DateTime::setTimezone can not set timezones without ID +--CREDITS-- +Boro Sitnikovski +--INI-- +date.timezone = UTC +--FILE-- +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