php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #51866 DateTime::createFromFormat does not match documentation
Submitted: 2010-05-20 04:01 UTC Modified: 2010-05-22 21:23 UTC
From: smalyshev at sugarcrm dot com Assigned: salathe (profile)
Status: Closed Package: Date/time related
PHP Version: 5.3SVN-2010-05-20 (SVN) OS: *
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: smalyshev at sugarcrm dot com
New email:
PHP Version: OS:

 

 [2010-05-20 04:01 UTC] smalyshev at sugarcrm dot com
Description:
------------
The manual for DateTime::createFromFormat says: 

 Format accepted by date().

If format does not contain the character ! then portions of the date/time value specified in format but not specified in time will be set to the current system time. 

However if you specify format like "d-m-Y H:i" and provide datetime string that does not contain time, parsing would fail - even though the manual says if time string does not contain parts from format it should use current system.


Test script:
---------------
<?php

$date = DateTime::createFromFormat("d-m-Y H:i", "25-10-2007");
var_dump($date);


Expected result:
----------------
Something like:
object(DateTime)#1 (3) {
  ["date"]=>
  string(19) "2007-10-25 18:58:31"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(19) "America/Los_Angeles"
}



Actual result:
--------------
bool(false)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-20 04:02 UTC] stas@php.net
It also would be nice if this function could ignore extra input after the parsing and/or return where it stopped.
 [2010-05-20 10:20 UTC] salathe@php.net
-Type: Bug +Type: Documentation Problem -Assigned To: +Assigned To: derick
 [2010-05-20 10:20 UTC] salathe@php.net
I believe this is an issue of documentation rather than implementation, the quoted 
portion of the manual describes different behaviour than what the code appears to 
do.  I'll assign this to Derick to confirm one way or the other.
 [2010-05-21 00:05 UTC] stas@php.net
-Type: Documentation Problem +Type: Bug
 [2010-05-21 00:05 UTC] stas@php.net
I don't think it's a docs problem - it'd be much better if DateTime actually did what the docs say - at least as one of the options. Without it, if you have a string with date in it, you can not really find out where the date begins and ends and have no way to do parsing of partial dates.
 [2010-05-22 19:07 UTC] derick@php.net
-Assigned To: derick +Assigned To: salathe
 [2010-05-22 19:07 UTC] derick@php.net
The docs are wrong here. If you specify a format letter, that information needs to be there.
 [2010-05-22 21:13 UTC] salathe@php.net
Automatic comment from SVN on behalf of salathe
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=299631
Log: Correct description of special ! character. Fixes #51866
 [2010-05-22 21:23 UTC] salathe@php.net
-Status: Assigned +Status: Closed -Type: Bug +Type: Documentation Problem
 [2010-05-22 21:23 UTC] salathe@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

The description of "!" now matches what the code does, as well as the example that was already available in the documentation.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC