Bug #64975 [Com]: createFromFormat Error parsing when AM PM not at the end

From: Date: Fri, 22 Apr 2016 05:18:35 +0000
Subject: Bug #64975 [Com]: createFromFormat Error parsing when AM PM not at the end
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200683@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=64975&edit=1

 ID:                 64975
 Comment by:         miken32 at gmail dot com
 Reported by:        dimka212 at gmail dot com
 Summary:            createFromFormat Error parsing when AM PM not at the
                     end
 Status:             Analyzed
 Type:               Bug
 Package:            Date/time related
 Operating System:   Any
 PHP Version:        Irrelevant
 Assigned To:        derick
 Block user comment: N
 Private report:     N

 New Comment:

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!


Previous Comments:
------------------------------------------------------------------------
[2014-05-09 12:20:03] 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.

------------------------------------------------------------------------
[2013-06-05 11:16:16] 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.)


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=64975&edit=1


Thread (6 messages)

« previous php.bugs (#200683) next »