ID: 42910 Updated by: [EMAIL PROTECTED] Reported By: php at michaelho dot com -Status: Assigned +Status: Closed Bug Type: Date/time related Operating System: Mac OS X 10.4.10 PHP Version: 5.2.4 Assigned To: derick New Comment:
This bug has been fixed in CVS. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. Thank you for the report, and for helping us make PHP better. Previous Comments: ------------------------------------------------------------------------ [2007-11-04 21:56:58] alex at kiesel dot name I also believe that there should be a possibility to distinguish between a timezone "constructed" by an GMT offset and one constructed by an timezone identifier. Here is a shorter reproducting script which shows the inconsistency: <?php putenv('TZ='); date_default_timezone_set('Australia/Sydney'); $date= date_create('2007-11-04 12:00:00+0200'); var_dump(date_format($date, 'O e')); ?> This prints: $ php date.php string(22) "+0200 Australia/Sydney" ------------------------------------------------------------------------ [2007-10-09 23:42:18] [EMAIL PROTECTED] This is expected behavior, but I'll check your claim about getName(). ------------------------------------------------------------------------ [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