Bug #14413 [Asn]: Passing a Unix timestamp in the constructor doesn't work (BC break)
| From: | mike at silverorange dot com | Date: | Wed, 25 Aug 2010 18:55:55 +0000 |
| Subject: | Bug #14413 [Asn]: Passing a Unix timestamp in the constructor doesn't work (BC break) | ||
| References: | 1 | Groups: | php.pear.bugs |
| Request: | Send a blank email to pear-bugs+get-4677@lists.php.net to get a copy of this message | ||
Edit report at http://pear.php.net/bugs/bug.php?id=14413&edit=1
ID: 14413
Updated by: mike@silverorange.com
Reported By: mike at silverorange dot com
Summary: Passing a Unix timestamp in the constructor doesn't
work (BC break)
Status: Assigned
Type: Bug
Package: Date
Operating System: Irrelevant
Package Version: CVS
PHP Version: 5.2.6
Assigned To: c01234
Roadmap Versions:
New Comment:
Is this patch ever going to be applied?
If it breaks BC, perhaps it should be the last parameter instead of the
second.
If it is not going to be applied, the docs should be fixed to not say a
timestamp can be
used in the constructor.
Previous Comments:
------------------------------------------------------------------------
[2009-01-01 03:53:48] doconnor
Breaking unit tests in Bug #2378 and Bug #8912
------------------------------------------------------------------------
[2008-12-07 17:56:33] gauthierm
It's worth noting that PHP's DateTime class accepts UNIX timestamps in
the constructor if they are prefixed with '@'. In this way they
distinguish between ISO-8601 and UNIX timestamps. For example:
$timestamp = '@' . $time;
$date = new DateTime($timestamp);
------------------------------------------------------------------------
[2008-07-28 09:45:45] gauthierm
Description:
------------
The constructor hands off to setDate() which only parses Unix timestamps
if the second parameter is set correctly. The constructor never passes
the second parameter to setDate() when a Unix timestamp is passed.
Since there is ambiguity between ISO 8601 formatted dates like
int(20080728) and Unix timestamps (int(20080728) is also a Unix time), a
new optional parameter must be passed to the constructor to allow
parsing Unix timestamps.
Test script:
---------------
<?php
require_once 'Date.php';
$date = new Date(time());
echo $date->getDate(DATE_FORMAT_ISO), "\n";
$date = new Date();
echo $date->getDate(DATE_FORMAT_ISO), "\n";
?>
Expected result:
----------------
2008-07-28 10:34:10
2008-07-28 10:34:10
Actual result:
--------------
0000-00-00 00:00:00
2008-07-28 10:34:10
------------------------------------------------------------------------
--
Edit this bug report at http://pear.php.net/bugs/bug.php?id=14413&edit=1