Skip to content

Fix/php vs icu format#15

Merged
ralflang merged 3 commits into
FRAMEWORK_6_0from
fix/php_vs_icu_format
May 22, 2026
Merged

Fix/php vs icu format#15
ralflang merged 3 commits into
FRAMEWORK_6_0from
fix/php_vs_icu_format

Conversation

@TDannhauer
Copy link
Copy Markdown
Contributor

Summary

Format::isPhpDateFormat() used str_contains() on PHP-specific format letters, so ICU locale shortcuts were misclassified as PHP date() syntax:

short and long match o (ISO week-year)
full matches u (microseconds)
Format::parse() then routed those patterns to DateTimeFormatter instead of IcuFormatter. Parsing failed for common prefs such as date_format_mini = short (e.g. 29.05.26 with pattern short), which broke consumers like horde/nag after #14.

Exclude ICU shortcuts short, medium, long, and full in isPhpDateFormat() before the character scan, consistent with IcuFormatter and Format::formatDate().

Changes

Format::isPhpDateFormat(): return false for ICU shortcuts
FormatParseTest: tests for shortcut rejection and Format::parse('29.05.26', 'short', 'de_DE')
Test plan

vendor/bin/phpunit test/Unit/FormatParseTest.php

Format::parse('29.05.26', 'short', 'de_DE') returns 2026-05-29

Format::isPhpDateFormat('short') is false; Format::isPhpDateFormat('Y-m-d') remains true

nag: save task due date with mini date format set to Short (no DateTimeFormatter parse error)
Fixes regression introduced by #14. Related: horde/nag (uses Format::parse() / Format::parseDateTime() for parseDate()).

Add check for ICU locale shortcuts in isPhpDateFormat method.
@TDannhauer TDannhauer requested a review from ralflang May 22, 2026 10:12
@ralflang
Copy link
Copy Markdown
Member

Let's rather not do this. strftime/icu is an almost perfectly distinguishable pattern, datetime has ambiguity exactly in the practically relevant area towards ICU. Let's auto-detect only ICU vs strftime and give ICU the first priority. Users of DateTime need to call DateTimeFormatter::parse directly.

PHP date() single-letter patterns (u, o, etc.) are ambiguous with ICU
patterns and locale shortcuts (short, long, full). Auto-detection is
only reliable for strftime (% prefix) vs ICU.

Format::parse() now only distinguishes strftime vs ICU, giving ICU
first priority. Callers needing PHP date() parsing should use
DateTimeFormatter::parse() directly.

Fixes ICU shortcut misclassification (e.g. 'short' matching 'o').
@ralflang ralflang merged commit 3831240 into FRAMEWORK_6_0 May 22, 2026
0 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants