Bug #67302 [Opn]: DateTime->setTimezone does not set TZ correctly

From: Date: Mon, 19 May 2014 12:24:06 +0000
Subject: Bug #67302 [Opn]: DateTime->setTimezone does not set TZ correctly
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185856@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67302&edit=1 ID: 67302 User updated by: alan at bulbstudios dot com Reported by: alan at bulbstudios dot com Summary: DateTime->setTimezone does not set TZ correctly Status: Open Type: Bug Package: Date/time related Operating System: OSX, Debian GNU/Linux PHP Version: 5.5.12 Block user comment: N Private report: N New Comment: The test script is actually: #!/usr/bin/env php <?php date_default_timezone_set('UTC'); echo date_default_timezone_get(), PHP_EOL; $utc = new DateTimeZone('UTC'); $time = DateTime::createFromFormat('Y-m-d H:i:s', '2014-05-19 11:30:00'); foreach (['BST', 'Etc/GMT+1', 'GMT+1', 'CEST'] as $abbr) { $time->setTimezone(new DateTimeZone($abbr)); echo "{$abbr}: {$time->format(DATE_RFC822)}", PHP_EOL; } Previous Comments: ------------------------------------------------------------------------ [2014-05-19 12:19:19] alan at bulbstudios dot com Description: ------------ Setting a timezone of either BST, GMT+1, Etc/GMT+1 or CEST on a DateTime object seems to modify the time of the object and set the timezone incorrectly. Works fine on PHP 5.4.28, barring the missing GMT+1. Test script: --------------- #!/usr/bin/env php <?php echo date_default_timezone_get(), PHP_EOL; $utc = new DateTimeZone('UTC'); $time = DateTime::createFromFormat('Y-m-d H:i:s', '2014-05-19 11:30:00'); foreach (['BST', 'GMT+1', 'CEST'] as $abbr) { $time->setTimezone(new DateTimeZone($abbr)); echo "{$abbr}: {$time->format(DATE_RFC822)}", PHP_EOL; } Expected result: ---------------- UTC BST: Mon, 19 May 14 12:30:00 +0100 Etc/GMT+1: Mon, 19 May 14 12:30:00 +0100 GMT+1: Mon, 19 May 14 12:30:00 +0100 CEST: Mon, 19 May 14 14:30:00 +0200 Actual result: -------------- UTC BST: Mon, 19 May 14 12:30:00 +0100 Etc/GMT+1: Mon, 19 May 14 11:30:00 -0100 GMT+1: Mon, 19 May 14 13:30:00 +0100 CEST: Mon, 19 May 14 14:30:00 +0100 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=67302&edit=1

« previous php.bugs (#185856) next »