Bug #71061 [NEW]: DateTime[Immutable]->setTimezone doesn't update local time

From: Date: Tue, 08 Dec 2015 14:16:47 +0000
Subject: Bug #71061 [NEW]: DateTime[Immutable]->setTimezone doesn't update local time
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-197696@lists.php.net to get a copy of this message
From:             m dot bennewitz at dcmn dot com
Operating system: Linux
PHP version:      7.0.0
Package:          Date/time related
Bug Type:         Bug
Bug description:DateTime[Immutable]->setTimezone doesn't update local time

Description:
------------
When changing the time zone from UTC to -09:00 the local date gets
updated but after changing it back to UTC it doesn't.

Both DateTime and DateTimeImmutable have the same issue.

Test script:
---------------
$date = new DateTime('2015-09-01+00:00');
var_dump($date);

$date = $date->setTimezone(new DateTimeZone('-09:00'));
var_dump($date);

$date = $date->setTimezone(new DateTimeZone('+00:00'));
var_dump($date);

$date = new DateTimeImmutable('2015-09-01+00:00');
var_dump($date);

$date = $date->setTimezone(new DateTimeZone('-09:00'));
var_dump($date);

$date = $date->setTimezone(new DateTimeZone('+00:00'));
var_dump($date);

Expected result:
----------------
object(DateTime)#1 (3) {
  ["date"]=> string(26) "2015-09-01 00:00:00.000000"
  ["timezone_type"]=> int(1)
  ["timezone"]=> string(6) "+00:00"
}
object(DateTime)#1 (3) {
  ["date"]=> string(26) "2015-08-31 15:00:00.000000"
  ["timezone_type"]=> int(1)
  ["timezone"]=> string(6) "-09:00"
}
object(DateTime)#1 (3) {
  ["date"]=> string(26) "2015-09-01 00:00:00.000000"
  ["timezone_type"]=> int(1)
  ["timezone"]=> string(6) "+00:00"
}
object(DateTimeImmutable)#2 (3) {
  ["date"]=> string(26) "2015-09-01 00:00:00.000000"
  ["timezone_type"]=> int(1)
  ["timezone"]=> string(6) "+00:00"
}
object(DateTimeImmutable)#3 (3) {
  ["date"]=> string(26) "2015-08-31 15:00:00.000000"
  ["timezone_type"]=> int(1)
  ["timezone"]=> string(6) "-09:00"
}
object(DateTimeImmutable)#1 (3) {
  ["date"]=> string(26) "2015-09-01 00:00:00.000000"
  ["timezone_type"]=> int(1)
  ["timezone"]=> string(6) "+00:00"
}

Actual result:
--------------
object(DateTime)#1 (3) {
  ["date"]=> string(26) "2015-09-01 00:00:00.000000"
  ["timezone_type"]=> int(1)
  ["timezone"]=> string(6) "+00:00"
}
object(DateTime)#1 (3) {
  ["date"]=> string(26) "2015-08-31 15:00:00.000000"
  ["timezone_type"]=> int(1)
  ["timezone"]=> string(6) "-09:00"
}
object(DateTime)#1 (3) {
  ["date"]=> string(26) "2015-08-31 15:00:00.000000"
  ["timezone_type"]=> int(1)
  ["timezone"]=> string(6) "+00:00"
}
object(DateTimeImmutable)#2 (3) {
  ["date"]=> string(26) "2015-09-01 00:00:00.000000"
  ["timezone_type"]=> int(1)
  ["timezone"]=> string(6) "+00:00"
}
object(DateTimeImmutable)#3 (3) {
  ["date"]=> string(26) "2015-08-31 15:00:00.000000"
  ["timezone_type"]=> int(1)
  ["timezone"]=> string(6) "-09:00"
}
object(DateTimeImmutable)#1 (3) {
  ["date"]=> string(26) "2015-08-31 15:00:00.000000"
  ["timezone_type"]=> int(1)
  ["timezone"]=> string(6) "+00:00"
}

-- 
Edit bug report at https://bugs.php.net/bug.php?id=71061&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=71061&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=71061&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=71061&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=71061&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=71061&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=71061&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=71061&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=71061&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=71061&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=71061&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=71061&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=71061&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=71061&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71061&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=71061&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=71061&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=71061&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71061&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=71061&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=71061&r=mysqlcfg



Thread (2 messages)

« previous php.bugs (#197696) next »