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)    

 [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


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