php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64975 createFromFormat Error parsing when AM PM not at the end
Submitted: 2013-06-05 11:16 UTC Modified: 2017-10-24 05:24 UTC
Votes:9
Avg. Score:4.0 ± 0.8
Reproduced:8 of 8 (100.0%)
Same Version:5 (62.5%)
Same OS:3 (37.5%)
From: dimka212 at gmail dot com Assigned: derick (profile)
Status: Assigned Package: Date/time related
PHP Version: Irrelevant OS: Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dimka212 at gmail dot com
New email:
PHP Version: OS:

 

 [2013-06-05 11:16 UTC] dimka212 at gmail dot com
Description:
------------
$date = DateTime::createFromFormat('d M Y A h:i', '11 Mar 2013 PM 3:34');
Returns:   [12] => Unexpected data found.

Works only in this case:
$date = DateTime::createFromFormat('d M Y h:i A', '11 Mar 2013 3:34 PM');


Test script:
---------------
$date = DateTime::createFromFormat('d M Y A h:i', '11 Mar 2013 PM 3:34');
if(!$date) echo 'Doesn\'t work =(';

Expected result:
----------------
Returns DateTime object

Actual result:
--------------
False
(Unexpected data found.)

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-05-09 12:20 UTC] daverandom@php.net
This behaviour is not in itself a bug.

The issue is that the wrong error is reported, and the root cause of this is actually a bug in the way date_get_last_errors() works rather than the date parsing mechanism.

As fixing this would be a BC break, I have submitted a patch that ensures that in this specific case the correct error is reported.
 [2014-05-09 20:38 UTC] daverandom@php.net
-Status: Open +Status: Analyzed -Operating System: Windows +Operating System: Any
 [2014-06-08 21:35 UTC] stas@php.net
-Assigned To: +Assigned To: derick
 [2016-04-22 05:18 UTC] miken32 at gmail dot com
If the behaviour is "not a bug" then documentation should also be updated to mention that AM/PM will not be parsed until after an hour is parsed.

I fail to see why this limitation is in any way necessary; some explanation would be helpful!
 [2017-10-24 05:24 UTC] kalle@php.net
-Status: Analyzed +Status: Assigned
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC