php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50392 date_create_from_format enforces 6 digits for 'u' format character
Submitted: 2009-12-06 10:53 UTC Modified: 2010-03-07 14:08 UTC
From: grodny at oneclick dot sk Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.3.1 OS: *
Private report: No CVE-ID: None
 [2009-12-06 10:53 UTC] grodny at oneclick dot sk
Description:
------------
As a result of fixing bug #45554, 'u' format character now requires exactly 6 digits of microsecond part during parsing.

Patch fragment:
...
if ((f = timelib_get_nr((char **) &ptr, 6)) == TIMELIB_UNSET || ptr - tptr != 6) {
...

Is check for exactly 6 digits really necessary, while other format characters are more benevolent about number of digits being parsed?


Reproduce code:
---------------
date_default_timezone_set('Europe/Bratislava');
var_dump(date_create_from_format('Y-m-d H:i:s.u', '2009-03-01 18:00:00.0'));

Expected result:
----------------
object(DateTime)#1 (3) {
  ["date"]=>
  string(19) "2009-03-01 18:00:00"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(17) "Europe/Bratislava"
}


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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-06 12:11 UTC] [email protected]
Hi,

I guess it's not really required, I'll have a look (in a bit).

Derick
 [2009-12-15 12:34 UTC] [email protected]
Automatic comment from SVN on behalf of iliaa
Revision: http://svn.php.net/viewvc/?view=revision&revision=292162
Log: Fixed bu #50392	(date_create_from_format() enforces 6 digits for 'u' format character)
 [2009-12-15 12:40 UTC] [email protected]
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.


 [2010-02-10 14:32 UTC] [email protected]
Reopening as this bug was fixed incorrectly. It would treat "0010" as "000010" which is not what it is meant to do. The test case didn't properly test the values either.
 [2010-02-10 16:23 UTC] [email protected]
Automatic comment from SVN on behalf of derick
Revision: http://svn.php.net/viewvc/?view=revision&revision=294854
Log: - Added a test case for bug #45866
- Fixed tests: oo_002, bug46268
- Fixed bug #50930 (Wrong date by php_date.c patch with ancient gcc/glibc
  versions).
- Make sure faulty strings passed to DateTime::modify() notify the user.
- Revert fix for bug #50392 as it was fixed wrongly without a proper test case.
- Fixed a bug with the 'r' formatting function as the default buffer size that
  was allocated only fit 4 digit years.
 [2010-02-11 11:11 UTC] [email protected]
Automatic comment from SVN on behalf of pajoye
Revision: http://svn.php.net/viewvc/?view=revision&revision=294880
Log: - merge fix for: #45866,#50930, revert fix for #50392, Fixed a bug with the 'r' formatting function, added or fixed tests for #45866 and #46268
 [2010-03-07 14:08 UTC] [email protected]
Automatic comment from SVN on behalf of derick
Revision: http://svn.php.net/viewvc/?view=revision&revision=295921
Log: - Fixed bug #50392 (date_create_from_format enforces 6 digits for 'u' format
  character).
 [2010-03-07 14:08 UTC] [email protected]
-Status: Assigned +Status: Closed
 [2010-03-07 14:08 UTC] [email protected]
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-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 20 12:00:03 2025 UTC