php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71061 DateTime[Immutable]->setTimezone doesn't update local time
Submitted: 2015-12-08 14:16 UTC Modified: 2015-12-08 21:33 UTC
From: m dot bennewitz at dcmn dot com Assigned:
Status: Duplicate Package: Date/time related
PHP Version: 7.0.0 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: m dot bennewitz at dcmn dot com
New email:
PHP Version: OS:

 

 [2015-12-08 14:16 UTC] m dot bennewitz at dcmn dot com
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"
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-12-08 21:33 UTC] requinix@php.net
-Status: Open +Status: Duplicate
 [2015-12-08 21:33 UTC] requinix@php.net
Duplicate of bug #69916
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 10:01:26 2024 UTC