From:  flintweather@gmail.com ("weather")
Date:  19 Sep 2018 05:19:27 Hong Kong Time
Newsgroup:  news.php.net/php.pear.bugs
Subject:  

[PEAR-BUG] Bug #14413 [Com]: Passing a Unix timestamp in the constructor doesn't work (BC break)

NNTP-Posting-Host:  null

Edit report at http://pear.php.net/bugs/bug.php?id=14413&edit=1

 ID:               14413
 Comment by:       weather
 Reported By:      flintweather at gmail dot com
 Summary:          Passing a Unix timestamp in the constructor doesn't
                   work (BC break)
 Status:           Open
 Type:             Bug
 Package:          Date
 Operating System: Irrelevant
 Package Version:  CVS
 PHP Version:      5.2.6
 New Comment:

Patched as of https://github.com/pear/Date/commit/ee6e1ff
It should be BC, still accepting original boolean but now accepting an
args array allowing for overridden defaults.


Previous Comments:
------------------------------------------------------------------------

[2010-08-25 18:55:55] gauthierm

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.

------------------------------------------------------------------------

[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:
---------------
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