DateTime::createFromFormat # separation doesn't allow a space
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
The following code:
<?php
var_dump( DateTime::createFromFormat( '!d#M#Y H#i' , '07 Oct 2024 11:47' ) );
Resulted in this output:
bool(false)
But I expected this output instead:
object(DateTime)#1 (3) {
["date"]=>
string(26) "2024-10-07 11:47:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(13) "Europe/London"
}
From the PHP manual, the # should allow the following separation characters:
One of the following separation symbol: ;, :, /, ., ,, -, ( or )
This appears to include space, between . and -, but from the code above it doesn't parse the date string with a space. If I replace the format string with '!d M Y H#i ' it works as expected, so the : in the time is being handled by #, and the numeric parts fit the date format characters.
If I replace the spaces in the date string with - then it works as expected, so it's not anything else in the date string causing the issue.
var_dump( DateTime::createFromFormat( '!d#M#Y H#i' , '07-Oct-2024 11:47' ) );
object(DateTime)#1 (3) {
["date"]=>
string(26) "2024-10-07 11:47:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(13) "Europe/London"
}
PHP Version
PHP 8.3.9
Operating System
Windows Server 2016 ( IIS using PHP binaries from http://windows.php.net )
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the DateTime::createFromFormat entry point and reproduce the two format examples from the issue on PHP 8.3.9. The fix is complete when # accepts spaces as documented while continuing to parse the hyphenated and time-separator examples correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100