DateTime::createFromFormat # separation doesn't allow a space
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- C
- Sterne
- 40.4k
- Forks
- 8.1k
- Ø Merge
- 2 T. 13 Std.
- Gemergte PRs (30 T.)
- 96
Beschreibung
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 )
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne am Einstiegspunkt DateTime::createFromFormat und reproduziere die beiden Formatbeispiele aus dem Issue unter PHP 8.3.9. Die Korrektur ist vollständig, wenn # wie dokumentiert Leerzeichen akzeptiert und weiterhin die Beispiele mit Bindestrichen und Zeittrennzeichen korrekt geparst werden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- php
- Bereich
- backend
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 52/100