Fix: use extension Intl instead of strftime() for date format '(locale)' - #35
Open
peterschade wants to merge 1 commit into
Open
Fix: use extension Intl instead of strftime() for date format '(locale)'#35peterschade wants to merge 1 commit into
peterschade wants to merge 1 commit into
Conversation
strftime() is deprecated since PHP 8.1 and deleted since PHP 9.0, so the date format '(locale)' raises a deprecation notice and is going to stop working. The format is now converted into the ICU syntax and merged with IntlDateFormatter, using the locale set with setlocale() for category LC_TIME, like strftime() did. Locales 'C' and 'POSIX' are mapped to 'en_US_POSIX' so that the result stays in English when no locale is set. If extension Intl is not available, then the format falls back on date() which gives English names. Unit tests are added in FrmTestCase. The localized ones are skipped when the system locale or extension Intl is missing.
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.
Problem
The date format
(locale)is merged withstrftime(), which is deprecated since PHP 8.1 and deleted since PHP 9.0. So the format currently raises a deprecation notice, and it is going to raise a fatal error.This is the only way to get localized month and day names with TBS, since
mmm/mmmmare merged withdate()which always gives English names.Fix
The format is converted into the ICU syntax and merged with
IntlDateFormatter(extension Intl, bundled with PHP and enabled by default since PHP 8.0):setlocale()for categoryLC_TIME, likestrftime()did, so existing applications do not have to be changed,CandPOSIXare mapped toen_US_POSIXin order to keep English names when no locale is set,date()which gives English names, like a non(locale)format.The format parser is not changed: the ICU format is deduced from the PHP format (
str_us) which is already prepared byf_Misc_CheckArgFormat().Example with
setlocale(LC_TIME, 'de_DE.UTF-8'):Notes
xx(ordinal suffix) has no ICU equivalent, so it is ignored in a(locale)format. This is the same behavior as before since%had no equivalent forstrftime()either.nov.forfr_FRinstead ofnov).Unit tests
Unit tests are added in
FrmTestCase(the commented locale test is replaced):fr_FR) or extension Intl is missing.Result on PHP 8.3: 398 passes, 0 failures (392 passes before the patch).