Fix/php vs icu format#15
Merged
Merged
Conversation
Add check for ICU locale shortcuts in isPhpDateFormat method.
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').
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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()).