Req #62166 [Opn->Nab]: createfromFormat assign current time by default when reading date only string.
| From: | stas@php.net | Date: | Sat, 14 Jul 2012 23:51:03 +0000 |
| Subject: | Req #62166 [Opn->Nab]: 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-171959@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: Not a bug
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:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Previous Comments:
------------------------------------------------------------------------
[2012-07-07 20:29:01] lenzai2004-dev at yahoo dot fr
Thank you for your Help. Sorry for misreading documentation.
------------------------------------------------------------------------
[2012-07-07 19:59:41] stas@php.net
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?
------------------------------------------------------------------------
[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