Bug #64975 [Asn->Csd]: createFromFormat Error parsing when AM PM not at the end
| From: | derick@php.net | Date: | Wed, 18 Aug 2021 19:33:54 +0000 |
| Subject: | Bug #64975 [Asn->Csd]: createFromFormat Error parsing when AM PM not at the end | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-235948@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
Updated by: derick@php.net
Reported by: dimka212 at gmail dot com
Summary: createFromFormat Error parsing when AM PM not at the
end
-Status: Assigned
+Status: Closed
Type: Bug
Package: Date/time related
Operating System: Any
PHP Version: Irrelevant
Assigned To: derick
Block user comment: N
Private report: N
New Comment:
The fix for this bug has been committed.
If you are still experiencing this bug, try to check out latest source from https://github.com/php/php-src and re-test.
Thank you for the report, and for helping us make PHP better.
This is fixed for PHP 8.0(.10) and later, where it now correctly shows the error message:
<?php
$date = DateTime::createFromFormat('d M Y A h:i', '11 Mar 2013 PM 3:34');
var_dump(DateTime::getLastErrors());
?>
array(4) {
["warning_count"]=>
int(0)
["warnings"]=>
array(0) {
}
["error_count"]=>
int(1)
["errors"]=>
array(1) {
[12]=>
string(51) "Meridian can only come after an hour has been found"
}
}
Previous Comments:
------------------------------------------------------------------------
[2016-04-22 05:18:33] 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!
------------------------------------------------------------------------
[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