Req #62166 [Opn->Fbk]: createfromFormat assign current time by default when reading date only string.

From: Date: Sat, 07 Jul 2012 19:59:41 +0000
Subject: Req #62166 [Opn->Fbk]: createfromFormat assign current time by default when reading date only string.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-171783@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=62166&edit=1 ID: 62166 Updated by: stas@php.net Reported by: lenzai2004-dev at yahoo dot fr Summary: createfromFormat assign current time by default when reading date only string. -Status: Open +Status: Feedback Type: Feature/Change Request Package: Date/time related Operating System: Ubuntu 11.10 64bits PHP Version: 5.3.13 Block user comment: N Private report: N New Comment: The documentation for date_create_from_format states: ! Resets all fields (year, month, day, hour, minute, second, fraction and timzone information) to the Unix Epoch Without !, all fields will be set to the current date and time. So maybe the format should be !Y-m-d? Would that solve the issue? Previous Comments: ------------------------------------------------------------------------ [2012-05-26 10:45:49] lenzai2004-dev at yahoo dot fr Description: ------------ DateTime:createFromFormat() and DateTime::__construct are not consistent for parsing dates. __construct sets default time at 00:00:00 DateTime::createFromFormat() sets default time at current time Test script: --------------- var_export(DateTime::createFromFormat("Y-m-d","2012-05-11")); var_export(new DateTime("2012-05-11")); Expected result: ---------------- DateTime::__set_state(array( 'date' => '2012-05-11 00:00:00', 'timezone_type' => 3, 'timezone' => 'Asia/Chongqing', )) DateTime::__set_state(array( 'date' => '2012-05-11 00:00:00', 'timezone_type' => 3, 'timezone' => 'Asia/Chongqing', )) Actual result: -------------- DateTime::__set_state(array( 'date' => '2012-05-11 18:34:45', 'timezone_type' => 3, 'timezone' => 'Asia/Chongqing', )) DateTime::__set_state(array( 'date' => '2012-05-11 00:00:00', 'timezone_type' => 3, 'timezone' => 'Asia/Chongqing', )) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=62166&edit=1

« previous php.bugs (#171783) next »