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
"P" format for ::createFromFormat swallows string literals #17159
When creating dates from PDF time strings, the following format is used: (D:20241122222357+08:00). To convert these strings to DateTimeImmutable objects, dates without timezones can be parsed with the following format:
\DateTimeImmutable::createFromFormat('\(\D\:YmdHis\)', '(D:20241122222357)'); // object(DateTimeImmutable) for
When modifying the format to include a timezone modifier (P), this breaks:
To allow the timezone modifier to be present, the format has to be modified, and the last \) escape for the closing bracket has to be removed in the format:
It looks like the "P" modifier swallows any closing brackets. This makes the format less readable, as the opening bracket has to be included (\(), while the closing bracket doesn't have to be included (\))
Yeah timelib_parse_zone eats as many ( or horizontal whitespace as possible at the start, and then eats as many ) as possible at the end. One would assume that the number of ( and ) eaten must match, which would fix this issue. However, that may also break BC.
Activity
ndossche commentedon Dec 14, 2024
Yeah
timelib_parse_zoneeats as many(or horizontal whitespace as possible at the start, and then eats as many)as possible at the end. One would assume that the number of(and)eaten must match, which would fix this issue. However, that may also break BC.php-src/ext/date/lib/parse_date.re
Lines 994 to 996 in 7bfd198
So a patch like this works, and your sample code now returns the right object instead of false:
cc @derickr for opinions on the matter
ndossche commentedon Sep 15, 2025
Fix merged for the next releases.