|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-10-09 23:33 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 02 17:00:01 2025 UTC |
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"