You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DateTime::createFromFormat: Parsing TZID string is too greedy #9700
It is a documentation problem DateTime::createFromFormat accepts the datetime string but is valid on the user side if the format is not repeated more than once, "p" and "e" or "e" and "e" is a repeat. Because the date to be created must be valid
<?phpvar_dump(DateTime::createFromFormat('Y-m-d\TH:i:sP e e', '2022-02-18T00:00:00+23:00 Europe/Berlin Europe/Rome'));
var_dump(var_dump(DateTime::GetLastErrors()));
?>
Expected Result is Europe/Rome not Europe/Berlin or +23:00 (For me output date Expected is timezone: T from ISO 8601 , without Europe/Berlin or Europe/Rome ex1. 2022-02-17T23:00:00 or ex2. 2022-02-18T00:00:00+01:00)
It would be better to create a new format, instead of validating the final part of a string with the rest of the string
Special format: DateTimeImmutable::createFromFormat, date_create_immutable_from_format, DateTime::createFromFormat
and date_create_from_format: output date default hide, esplicit show: DateTimeInterface::format, DateTimeImmutable::format, DateTime::format
and date_format (function format) 'Y-m-d\TH:i:s output date[e output date]';
changed the title [-]DateTime::createFromFormat with two identical timezones resolves to false[/-][+]DateTime::createFromFormat: Parsing TZID string is too greedy[/+]on Oct 18, 2022
Activity
iluuu1994 commentedon Oct 10, 2022
It seems the square brackets are the problem.
'Y-m-d\TH:i:sP e'works fine. https://3v4l.org/LJlNJcmb69 commentedon Oct 10, 2022
https://3v4l.org/4bcK8 clarifies; the timezone would be
[Europe/Berlin].iluuu1994 commentedon Oct 10, 2022
Europe/Berlin]actually, probably. I'm assuming the parser just doesn't stop on]. https://3v4l.org/PVnaccmb69 commentedon Oct 10, 2022
Ah, right, @iluuu1994! Fixing exactly this issue would be trivial:
Anyhow, this is a timelib issue, but I don't think we need to report upstream, since @derickr is the ext/date maintainer as well.
hormus commentedon Oct 13, 2022
It is a documentation problem DateTime::createFromFormat accepts the datetime string but is valid on the user side if the format is not repeated more than once, "p" and "e" or "e" and "e" is a repeat. Because the date to be created must be valid
Expected Result is Europe/Rome not Europe/Berlin or +23:00 (For me output date Expected is timezone: T from ISO 8601 , without Europe/Berlin or Europe/Rome ex1. 2022-02-17T23:00:00 or ex2. 2022-02-18T00:00:00+01:00)
This bug:
It would be better to create a new format, instead of validating the final part of a string with the rest of the string
Special format: DateTimeImmutable::createFromFormat, date_create_immutable_from_format, DateTime::createFromFormat
and date_create_from_format: output date default hide, esplicit show: DateTimeInterface::format, DateTimeImmutable::format, DateTime::format
and date_format (function format) 'Y-m-d\TH:i:s output date[e output date]';
[-]DateTime::createFromFormat with two identical timezones resolves to false[/-][+]DateTime::createFromFormat: Parsing TZID string is too greedy[/+]derickr commentedon Oct 18, 2022
This is fixed in timelib now — I'll release and then merge this into PHP before the release of 8.0.26 and 8.1.13
derickr/timelib@cca0fe4
Fixed phpGH-9699, phpGH-9866, and phpGH-9880 (problems with diff); and …
derickr commentedon Nov 30, 2022
Now fixed, for PHP 8.1.14 and PHP 8.2.1.