Bug #55527 [Com]: DateTime::__construct throws Exception even when timezone is specified
| From: | good821 at 126 dot com | Date: | Mon, 29 Aug 2011 08:00:52 +0000 |
| Subject: | Bug #55527 [Com]: DateTime::__construct throws Exception even when timezone is specified | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-163010@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=55527&edit=1
ID: 55527
Comment by: good821 at 126 dot com
Reported by: john at zerocrates dot org
Summary: DateTime::__construct throws Exception even when
timezone is specified
Status: Open
Type: Bug
Package: Date/time related
Operating System: Linux
PHP Version: 5.3.8
Block user comment: N
Private report: N
New Comment:
http://www.official49ersstore.com/san-francisco-49ers-jerseys/anthony-davis-jersey-c-14_30.html Anthony
Davis Jersey
http://www.official49ersstore.com/san-francisco-49ers-jerseys/frank-gore-jersey-c-14_18.html Frank
Gore Jersey
Previous Comments:
------------------------------------------------------------------------
[2011-08-29 07:59:55] good821 at 126 dot com
http://www.officialpatriotsproshop.com/tom-brady-jersey-c-10_11.html Tom
Brady Authentic Jersey
http://www.officialpatriotsproshop.com/wes-welker-jersey-c-10_17.html Wes
Welker Authentic Jersey
------------------------------------------------------------------------
[2011-08-29 07:57:16] good821 at 126 dot com
http://www.chicagobearsjerseysshop.com/chris-williams-jersey-c-23.html
Chris Williams Jersey Bears
------------------------------------------------------------------------
[2011-08-29 07:53:57] junxing dot lin at yahoo dot com
http://www.chihaironline.net
------------------------------------------------------------------------
[2011-08-28 22:23:49] john at zerocrates dot org
Description:
------------
The DateTime constructor throws an Exception warning that it is not safe to rely
on the system's timezone settings if you try to construct a DateTime object and
haven't somehow specified a timezone, whether by using date_default_timezone_set,
the date.timezone setting, or the $timezone argument of DateTime itself.
However, there is another way to specify the timezone for a DateTime object, by
passing a time string which includes a timezone as the first argument to the
constructor. When such a string is given, the $timezone argument is ignored and
the timezone given in the string is always used.
However, this doesn't prevent the Exception from being thrown, even though a
timezone is being specified. To avoid the Exception, you have to have a default
timezone set, or you have to pass a DateTimeZone as the second argument, even
though neither would actually be used for creating the object.
Test script:
---------------
<?php
ini_set('date.timezone', NULL);
try {
$date = new DateTime('2011-08-28T00:00:00+0000');
echo $date->format('O');
} catch (Exception $e) {
echo 'Exception thrown.';
}
echo PHP_EOL;
date_default_timezone_set('America/New_York');
try {
$date = new DateTime('2011-08-28T00:00:00+0000');
echo $date->format('O');
} catch (Exception $e) {
echo 'Exception thrown.';
}
Expected result:
----------------
+0000
+0000
Actual result:
--------------
Exception thrown.
+0000
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=55527&edit=1