Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.5.0a4

Bug #14413 Passing a Unix timestamp in the constructor doesn't work (BC break)
Submitted: 2008-07-28 13:45 UTC
From: gauthierm Assigned:
Status: Open Package: Date (version CVS)
PHP Version: 5.2.6 OS: Irrelevant
Roadmaps: (Not assigned)    
Subscription  


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 27 - 23 = ?

 
 [2008-07-28 13:45 UTC] gauthierm (Michael Gauthier)
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

Comments

 [2008-12-07 22:56 UTC] gauthierm (Michael Gauthier)
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);
 [2009-01-01 08:53 UTC] doconnor (Daniel O'Connor)
Breaking unit tests in Bug #2378 and Bug #8912
 [2010-08-25 22:55 UTC] gauthierm (Michael Gauthier)
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.
 [2018-09-18 21:16 UTC] weather (Rick Yust)
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.