php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67302 DateTime->setTimezone does not set TZ correctly
Submitted: 2014-05-19 12:19 UTC Modified: 2016-06-29 12:11 UTC
From: alan at bulbstudios dot com Assigned: cmb (profile)
Status: Duplicate Package: Date/time related
PHP Version: 5.5.12 OS: OSX, Debian GNU/Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: alan at bulbstudios dot com
New email:
PHP Version: OS:

 

 [2014-05-19 12:19 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-05-19 12:24 UTC] alan at bulbstudios dot com
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;
}
 [2014-05-19 14:12 UTC] alan at bulbstudios dot com
A multi-version test case is available at: http://3v4l.org/mvReq
 [2014-05-19 15:02 UTC] alan at bulbstudios dot com
Another test case that shows the time is preserved when using a cloned DateTime, and also that the DateTimeZone offsets appear to be causing issues: http://3v4l.org/QpJYP
 [2014-05-20 11:24 UTC] arjen at react dot com
DateTimeZone objects cannot be constructed by passing a timezone abbreviation anymore since 5.5.10:

http://3v4l.org/Ui5ab#v5510

Probably broken by https://bugs.php.net/bug.php?id=45543
 [2014-05-23 08:00 UTC] arjen at react dot com
Already reported in https://bugs.php.net/bug.php?id=67077
 [2016-06-29 12:11 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2016-06-29 12:11 UTC] cmb@php.net
Duplicate of bug #67077.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Oct 04 22:01:27 2024 UTC