php / php/php-src

DateTime::createFromFormat # separation doesn't allow a space

オープン
#16,280 コメント 2 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Extension: date Feature Status: Needs Triage
主要言語
C
スター
40.4k
フォーク
8.2k
平均マージ
2日 13時間
マージ済み PR(30日)
96

説明

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 )

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

DateTime::createFromFormat のエントリポイントから始め、PHP 8.3.9 で issue にある 2 つのフォーマット例を再現してください。# がドキュメントどおりにスペースを受け入れ、ハイフンおよび時刻区切り文字の例を引き続き正しくパースできれば、修正は完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
php
領域
backend
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
52/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。