Open wisskid opened 2 years ago
Why try to emulate strftime() and for how long? You might as well align with PHP by offering two formatters [one for date() and another for Intl] or none.
I think that there is definitely no need to depend on the !mandatory use of certain extensions such as 'ext-intl' and especially third-party libraries, there should be a way to implement this functionality without this for the new Smarty 5, this would be the best option. As a last resort, if the functionality for some reason cannot be implemented in full as before, which is unlikely, then it is necessary to check for the presence of this extensions and if it is not present, use a different implementation. Also the vast majority of template engines and even large frameworks do not require the use of any extensions to work correctly, which is correct and does not scare away some part of users.
Please see https://github.com/smarty-php/smarty/issues/672#issuecomment-1159360142 and below. It's not as straightforward as you might think. But if you see a solution that does not require an extension, this would of course be preferred.
Well, I hope that we can still find some solution without using an additional 'ext-intl' extension. In any case, I think it would be absolutely correct not to require it forcibly and if it is not present, for example, use an implementation similar with symfony/polyfill-intl-icu with only supports the 'en' locale or something else, it will be enough for the vast majority of users.
Agree with lkppo, I think maybe it's time to get rid of strftime if it is not a must. Developers who still need strftime could polyfill it by themselves? (By reading some old issues & comments, I didn't figure out why strftime should be a must for new Smarty releases)
We've temporarily bridged the gap with https://packagist.org/packages/php81_bc/strftime .
We also changed servers from Debian based to Alpine Linux, and locales aren't really supported in Alpine, so we wanted an intl solution anyway. Installing ext-intl
was a no-brainer for us. We're still on Smarty 3, and use register_modifier
to override the default date_format
to keep our thousands of templates backwards compatible.
function dateFormat($date, string $format, ?string $locale = null): string
{
return \PHP81_BC\strftime($format, $date, $locale);
}
$smarty->register_modifier('date_format', 'dateFormat');
strftime
Provide a wrapper for
strftime
(to be removed in PHP9), possibly using alphp/strftime. This will require a new major, since alphp/strftime requires ext-intl.