Open JoshuaLuckers opened 3 years ago
I've been experimenting with this.
It looks like the PHP extension intl
would be a requirement if we're going to use IntlDateFormatter
.
Maybe we need a helper method/class that determines if it's installed and uses DateTime::format
which isn't locale aware otherwise.
Usage of IntlDateFormatter would be something along the lines of:
$locale = $this->modx->getOption('locale') ?? '';
$timezone = $this->modx->getOption('timezone') ?? '';
$formatter = new IntlDateFormatter($locale, IntlDateFormatter::SHORT, IntlDateFormatter::SHORT, $timezone);
return $formatter->format(new DateTime());
This issue has been mentioned on MODX Community. There might be relevant details there:
https://community.modx.com/t/whats-happening-with-the-strftime-and-date-output-modifiers/4826/3
Two weeks ago I released a SiteDash update that tracks available PHP extensions to see if requiring intl would be feasible. On a sample size so far of about 18% of sites connected to SiteDash, roughly 81% of those have the intl extension enabled. That's more than imagick (75%) but less than fileinfo (91%).
At those numbers I'd personally say we can conditionally use it in core; fallback to non-localised date()
with a warning-level error suggesting people to install intl for locale support.
Sounds good to me!
@Mark-H I'm proposing to make a start with this in 3.1. What do you think?
@Mark-H I'm proposing to make a start with this in 3.1. What do you think?
Just keep in mind this is only a deprecation warning and will continue to work until PHP 9 is released. We also need to consider places where this will cause BC breaks and keep compatibility for those on PHP <= 8.x for the MODX 3.x branch.
The
strftime()
function is called by the core in various places.In PHP 8.1 this will trigger a deprecation warning because the strftime() and gmstrftime() functions have been deprecated in favor of date()/DateTime::format() (for locale-independent formatting) or IntlDateFormatter::format() (for locale-dependent formatting).
References:
Environment