php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54316 DateTime::createFromFormat does not handle trailing '|' correctly
Submitted: 2011-03-19 12:34 UTC Modified: 2011-03-21 10:41 UTC
From: gtisza at gmail dot com Assigned: aharvey (profile)
Status: Closed Package: Date/time related
PHP Version: 5.3.6 OS: Windows XP, Debian 2.6
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
50 - 35 = ?
Subscribe to this entry?

 
 [2011-03-19 12:34 UTC] gtisza at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/datetime.createfromformat
---

According to the documentation:

"""
| - Resets all fields (year, month, day, hour, minute, second, fraction and timzone information) to the Unix Epoch if they have not been parsed yet

Y-m-d| will set the year, month and day to the information found in the string to parse, and sets the hour, minute and second to 0.
"""

Actually, it fails to parse the date (but works correctly when | is not at the end of the string).

Tested on PHP 5.3.2/Win XP and PHP 5.3.5/Debian. Can't test on 5.3.6 right now as windows.php.net seems unavailable.

Test script:
---------------
var_dump(DateTime::createFromFormat('Y-m-d|', '2011-02-02'));
$errors = DateTime::getLastErrors();
var_dump($errors['errors']);


Expected result:
----------------
object(DateTime)#1 (3) {
  ["date"]=>
  string(19) "2011-02-02 00:00:00"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(15) "Europe/Budapest"
}

array(0) {
}


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

array(1) {
  [10]=>
  string(12) "Data missing"
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-03-21 06:03 UTC] aharvey@php.net
-Status: Open +Status: Verified
 [2011-03-21 06:03 UTC] aharvey@php.net
Confirmed on a current 5.3 SVN build.
 [2011-03-21 10:29 UTC] aharvey@php.net
-Status: Verified +Status: Assigned -Assigned To: +Assigned To: aharvey
 [2011-03-21 10:41 UTC] aharvey@php.net
Automatic comment from SVN on behalf of aharvey
Revision: http://svn.php.net/viewvc/?view=revision&revision=309493
Log: Fix bug #54316 (DateTime::createFromFormat does not handle trailing '|'
correctly).
 [2011-03-21 10:41 UTC] aharvey@php.net
-Status: Assigned +Status: Closed
 [2011-03-21 10:41 UTC] aharvey@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.


 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Jun 16 01:01:28 2019 UTC