Skip to content

DateTime::createFromFormat: Parsing TZID string is too greedy #9700

Closed
@christoph-kluge

Description

@christoph-kluge

Description

Discovered this issue while importing a data-set from a third party.

The following code:

<?php
var_dump(DateTime::createFromFormat('Y-m-d\TH:i:sP[e]', '2022-02-18T00:00:00+01:00[Europe/Berlin]'));

https://3v4l.org/W9SPY

Resulted in this output:

bool(false)

But I expected this output instead:

object(DateTime)#1 (3) {
  ["date"]=>
  string(26) "2022-02-18 00:00:00.000000"
  ["timezone_type"]=>
  int(1)
  ["timezone"]=>
  string(6) "+01:00"
}

PHP Version

8.1.9 (discovered with 7.2.24)

Operating System

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions