#49480 [Opn->Csd]: DateTime::createFromFormat uses current system time to fill missing fields

From: Date: Sat, 12 Sep 2009 09:09:52 +0000
Subject: #49480 [Opn->Csd]: DateTime::createFromFormat uses current system time to fill missing fields
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-2770@lists.php.net to get a copy of this message
ID: 49480 Updated by: torben@php.net Reported By: grodny at oneclick dot sk -Status: Open +Status: Closed Bug Type: Documentation problem PHP Version: 5.3.0 New Comment: This bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient. Thank you for the report, and for helping us make our documentation better. Previous Comments: ------------------------------------------------------------------------ [2009-09-12 09:09:39] svn@php.net Automatic comment from SVN on behalf of torben Revision: http://svn.php.net/viewvc/?view=revision&revision=288278 Log: Document how to cause unspecified portions of the time given to createFromFormat() to be initialized to zero. Addresses bug #49480. ------------------------------------------------------------------------ [2009-09-08 09:09:37] derick@php.net Let's keep it open though, so that it can be documented. ------------------------------------------------------------------------ [2009-09-08 07:34:00] grodny at oneclick dot sk Such inconsistency and non-determinism in simple DateTime instance creation without using format modifier(undocumented one) can't be called correct. It's just how it was done :) Thanks anyway for hint. ------------------------------------------------------------------------ [2009-09-06 10:44:05] derick@php.net This is correct behaviour, you can change it by using a format like: <?php var_dump( DateTime::createFromFormat('!Y-m-d', '2009-03-02') ); ?> object(DateTime)#1 (3) { ["date"]=> string(19) "2009-03-02 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/London" } ------------------------------------------------------------------------ [2009-09-06 06:48:54] grodny at oneclick dot sk Description: ------------ DateTime::createFromFormat uses current system time to fill missing fields instead of zero values, which leads to inconsistent comparsions and intervals returned by DateTime::diff. DateTime::createFromFormat('Y-m-d', '2009-03-02') should always create object(DateTime)#1 (3) { ["date"]=> string(19) "2009-03-02 00:00:00" ... } Reproduce code: --------------- <?php $A = DateTime::createFromFormat('Y-m-d', '2009-03-02'); sleep(2); $B = DateTime::createFromFormat('Y-m-d', '2009-03-02'); var_dump($A == $B); ?> Expected result: ---------------- bool(true) Actual result: -------------- bool(false) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=49480&edit=1

« previous php.doc.bugs (#2770) next »