Doc #65747 [Com]: DateTime __construct error
| From: | vascowhite at gmail dot com | Date: | Wed, 18 Dec 2013 22:59:40 +0000 |
| Subject: | Doc #65747 [Com]: DateTime __construct error | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-10721@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=65747&edit=1
ID: 65747
Comment by: vascowhite at gmail dot com
Reported by: mwiseman at dogandtuba dot com
Summary: DateTime __construct error
Status: Open
Type: Documentation Problem
Package: Date/time related
Operating System: Windows
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
That doesn't explain why DateTimeZone::construct() doesn't recognise a valid time zone
like 'z', nor does it explain why
$dateTime = new \DateTime(null, 'z');
raises an exception. If 'z' is a valid tz, it should not.
There is a bug in there somewhere.
Previous Comments:
------------------------------------------------------------------------
[2013-09-30 06:43:46] gabri dot ns at gmail dot com
It is not a bug, but a feature that not documented.
As requinix says, single character could be mean
military time zone. for example Z1500 mean 15 o'clock
current date at GMT.
Test script:
---------------
echo date('Y-m-d H:i:s', strtotime('Z1500'));
Actual result:
--------------
2013-09-30 22:00:00
my time zone is +7
please try to take a look at this documentation
http://php.net/datetime.construct
http://php.net/datetime.formats
http://php.net/datetime.formats.time
btw, thus single char timezone is already documented.
take a look at tz format.. it declared as [A-Za-z]{1,6}
------------------------------------------------------------------------
[2013-09-30 06:24:13] vascowhite at gmail dot com
Is the bug in the constructor of DateTimeZone then? This does not recognize the
single letter timezones.
$tz = new \DateTimeZone('z');
Will raise an exception.
------------------------------------------------------------------------
[2013-09-30 03:09:56] gabri dot ns at gmail dot com
IMO, the one that should be fixed is strtotime documentation,
since this behaviour came from thus function. As doumentation say,
the first argument should be time string, that -i think- will be
parsed by strtotime function.
Test script:
---------------
echo date('Y-m-d H:i:s',strtotime('now'))."\n";
echo date('Y-m-d H:i:s',strtotime('a'))."\n";
Actual result:
--------------
2013-09-30 10:07:18
2013-09-30 16:07:18
------------------------------------------------------------------------
[2013-09-29 22:43:05] requinix@php.net
Expected but undocumented behavior.
Single characters correspond to military timezones. See
http://en.wikipedia.org/wiki/List_of_military_time_zones
foreach (range("a", "z") as $l) {
if ($l == "j") continue;
printf("%s = %s\n", $l, (new DateTime($l))->format("r"));
}
So the list of timezones documentation should be updated to mention these.
------------------------------------------------------------------------
[2013-09-29 15:56:59] vascowhite at gmail dot com
Related To: Bug #65787
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=65747
--
Edit this bug report at https://bugs.php.net/bug.php?id=65747&edit=1