Skip to content

ext/intl: Use byte offsets in IntlDateFormatter parsing - #24126

Closed
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/aph-intl-datefmt-offset-units-l91k-84-work
Closed

iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/aph-intl-datefmt-offset-units-l91k-84-work

Conversation

@iliaal

@iliaal iliaal commented Oct 4, 2026

Copy link
Copy Markdown
Member

IntlDateFormatter::parse(), localtime() and parseToCalendar() handed the PHP byte offset straight to ICU, which counts UTF-16 code units, so any multibyte text before the date made parsing start in the wrong place and the returned offset come back short (an emoji prefix parsed "2017-10-12" as year 17). This converts the offset both ways the same way GH-23094 did for NumberFormatter.

Comment thread ext/intl/dateformat/dateformat_parse.c Outdated
IntlDateFormatter::parse(), localtime() and parseToCalendar() passed the
PHP byte offset to ICU, which expects a UTF-16 code-unit position, and
returned ICU's position unchanged. With multibyte text before the date,
parsing started at the wrong place and the returned offset was too
small. Convert the offset in both directions as phpGH-23094 did for
NumberFormatter, and reject an offset that splits a UTF-8 sequence. A
returned position inside a surrogate pair, which a partially matched
literal can produce, maps to the start of that character. The offset
helpers move into intl_convert.c and NumberFormatter now uses them too.
@iliaal
iliaal force-pushed the fix/aph-intl-datefmt-offset-units-l91k-84-work branch from dc74a76 to c051104 Compare October 5, 2026 11:34
@iliaal
iliaal requested a review from devnexen October 5, 2026 11:35
@iliaal iliaal closed this in 913e01c Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants