#42910 [Opn->Asn]: Constructing DateTime with TimeZone Indicator invalidates DateTimeZone

From: Date: Tue, 09 Oct 2007 23:42:18 +0000
Subject: #42910 [Opn->Asn]: Constructing DateTime with TimeZone Indicator invalidates DateTimeZone
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-118341@lists.php.net to get a copy of this message
ID: 42910 Updated by: derick@php.net Reported By: php at michaelho dot com -Status: Open +Status: Assigned Bug Type: Date/time related Operating System: Mac OS X 10.4.10 PHP Version: 5.2.4 -Assigned To: +Assigned To: derick New Comment: This is expected behavior, but I'll check your claim about getName(). Previous Comments: ------------------------------------------------------------------------ [2007-10-09 23:35:16] php at michaelho dot com Typo... the first sentence in the third paragraph should read: "My guess is that **IF** a timezone indicator is passed into the __construct() method..." ------------------------------------------------------------------------ [2007-10-09 23:33:36] php at michaelho dot com Description: ------------ When creating a new DateTime with an timezone indicator (e.g. "-0800"), it seems to ignore any DateTimeZone rules as specified either by the default_timezone setting OR by an explicit DateTimeZone parameter. Notice that in the example below, the engine no longer applies DateTimeZone rules for $bar, even though the engine still lists "America/Los_Angeles" as $bar's DateTimeZone value. My guess is that a timezone indicator is passed into the __construct() method, it will be very difficult for the engine to deduce the correct DateTimeZone rules to use for that DateTime object, and thus, no rules should be applied after this point. If this is the case, then at the very least $bar->getTimezone()->getName() should return something like 'Undefined' or 'Custom/-0800' or something like that, to correctly indicate it is no longer using 'America/Los_Angeles' timezone rules. Reproduce code: --------------- date_default_timezone_set('America/Los_Angeles'); $foo = new DateTime('2007-03-11'); $bar = new DateTime('2007-03-11T00:00:00-0800'); print $foo->format(DateTime::ISO8601) . ' - ' . $foo->getTimezone()->getName() . ' - ' . $foo->format('U') . "\r\n"; print $bar->format(DateTime::ISO8601) . ' - ' . $foo->getTimezone()->getName() . ' - ' . $bar->format('U') . "\r\n"; $foo->setDate(2007, 03, 12); $bar->setDate(2007, 03, 12); print $foo->format(DateTime::ISO8601) . ' - ' . $foo->getTimezone()->getName() . ' - ' . $foo->format('U') . "\r\n"; print $bar->format(DateTime::ISO8601) . ' - ' . $foo->getTimezone()->getName() . ' - ' . $bar->format('U') . "\r\n"; Expected result: ---------------- 2007-03-11T00:00:00-0800 - America/Los_Angeles - 1173600000 2007-03-11T00:00:00-0800 - America/Los_Angeles - 1173600000 2007-03-12T00:00:00-0700 - America/Los_Angeles - 1173682800 2007-03-12T00:00:00-0700 - America/Los_Angeles - 1173682800 Actual result: -------------- 2007-03-11T00:00:00-0800 - America/Los_Angeles - 1173600000 2007-03-11T00:00:00-0800 - America/Los_Angeles - 1173600000 2007-03-12T00:00:00-0700 - America/Los_Angeles - 1173682800 2007-03-12T00:00:00-0800 - America/Los_Angeles - 1173686400 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=42910&edit=1

« previous php.bugs (#118341) next »