[dev] strftime deprecation

Ralf Lang ralf.lang at ralf-lang.de
Sun Oct 9 18:41:39 UTC 2022


Am 08.10.22 um 15:40 schrieb Ralf Lang:
> Hello,
>
> I am thinking about the correct way to replace strftime calls in our 
> codebase.
> The strftime function is deprecated.
>
> It is aware of the currently set locale and uses a different way of 
> templating date strings than DateTimeInterface::format or 
> IntlDateFormatter::setPattern||
>
> https://www.php.net/manual/de/intldateformatter.format.php
> https://www.php.net/manual/de/datetime.format.php
>
> In some places, date formats are defined by Horde's prefs
>
> date_format
> date_format_mini
> time_format
> time_format_mini
>
> These settings are encoded in strftime mask formats and there are the 
> placeholders %X and %x to represent the locale's preferred date and 
> time settings.
>
> There are three possible routes.
>
> - Not deal with the issue now. Notices will be emitted and by PHP 9 
> this will eventually break.
> - Keep the prefs format and build a helper that adapts strftime-like 
> format strings to their DateTime equivalents.
> - Change the actual prefs values to native DateTime formats. Requires 
> additional effort to upgrade existing pref data. Cleanest solution 
> though.
On the way to a solution I fixed the Horde_Date_Utils::strftime2date 
static method for modern PHP (deprecated /e flag).

Now while this works quite OK for English, it does not translate 
weekdays, months etc.

The IntlDateFormatter requires the intl extension.
The real drawback is that it uses ISO format strings rather than the 
date_format strings. That would be yet another format and another 
translation to do.




More information about the dev mailing list