#43051 [Opn->Bgs]: new DateTime doesn't work well with @timestamp and timezone

From: Date: Sat, 20 Oct 2007 15:02:56 +0000
Subject: #43051 [Opn->Bgs]: new DateTime doesn't work well with @timestamp and timezone
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-118758@lists.php.net to get a copy of this message
ID: 43051 Updated by: derick@php.net Reported By: cezary at dodgeit dot com -Status: Open +Status: Bogus Bug Type: Date/time related Operating System: Mac OS X PHP Version: 5.2.4 New Comment: Please do not submit the same bug more than once. An existing bug report already describes this very problem. Even if you feel that your issue is somewhat different, the resolution is likely to be the same. Thank you for your interest in PHP. Duplicate of #43003 Previous Comments: ------------------------------------------------------------------------ [2007-10-20 07:35:05] cezary at dodgeit dot com Description: ------------ DateTime constructor fails to work well for me when using timestamps and time zones. $d = new DateTime('@1192864176', new DateTimeZone('America/ New_York')); echo $d->format(DATE_RFC3339); // outputs 2007-10-20T07:09:36+01:00 // why not -04:00? $d = new DateTime('@1192864176', new DateTimeZone('Antarctica/ Vostok')); echo $d->format(DATE_RFC3339); // outputs 2007-10-20T07:09:36+00:00 // why not +06:00? Besides it reports New York to be shifted +1 from UTC, it returns unadjusted time - it's 7 AM in UTC+1 and 7AM in UTC+0. A timestamp is always in UTC, but the resulting DateTime should be adjusted according to the given time zone in my opinion. My system clock and TZ environment variable are set to UTC. Reproduce code: --------------- $d = new DateTime('@1192864176', new DateTimeZone('America/ New_York')); echo $d->format(DATE_RFC3339); $d = new DateTime('@1192864176', new DateTimeZone('Antarctica/ Vostok')); echo $d->format(DATE_RFC3339); Expected result: ---------------- // 2007-10-20T03:09:36-04:00 // 2007-10-20T13:09:36+06:00 Actual result: -------------- // 2007-10-20T07:09:36+01:00 // 2007-10-20T07:09:36+00:00 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=43051&edit=1

« previous php.bugs (#118758) next »