From 40a81565e10968a115163add3c269cdd31a3a619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Wylega=C5=82a?= Date: Thu, 30 May 2024 11:35:39 +0200 Subject: [PATCH] FormHelper migration strftime to Intl. --- README.md | 2 +- composer.json | 2 +- lib/Cake/View/Helper/FormHelper.php | 6 ++---- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c12054ec2..2ea9f350d 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Here are steps I took to migrate my project through all versions to PHP 8.1, may ### Breaking changes -- In order to get rid of `strftime()` deprecation notices, it's required to switch to `IntlDateFormatter` class. This class is available in `intl` extension, fork requires `intl` extension to be enabled in PHP configuration. If you don't have `intl` extension, installing fork will result in error. Discussed (here)[https://github.com/kamilwylegala/cakephp2-php8/pull/64] and (here)[https://github.com/kamilwylegala/cakephp2-php8/issues/65]. +- In order to get rid of `strftime()` deprecation notices, it's required to switch to `IntlDateFormatter` class. This class is available in `intl` extension. Fork doesn't require it explicitly but to be able to use its functions Symfony ICU Polyfill is installed. To provide `strftime` behavior compatibility, `PHP81_BC\strftime` is used. `PHP81_BC` doesn't fully cover strftime, your code should work but there is a chance you'll get slightly different results. Discussed (here)[https://github.com/kamilwylegala/cakephp2-php8/pull/64] and (here)[https://github.com/kamilwylegala/cakephp2-php8/issues/65]. ## Installation diff --git a/composer.json b/composer.json index 18bd5abe1..8557694a0 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "suggest": { "ext-openssl": "You need to install ext-openssl or ext-mcrypt to use AES-256 encryption", "ext-mcrypt": "You need to install ext-openssl or ext-mcrypt to use AES-256 encryption", - "ext-intl": "Required to use IntlDateFormatter instead of strftime" + "ext-intl": "Required to use IntlDateFormatter instead of strftime, if not Symfony polyfill will be used." }, "require-dev": { "phpunit/phpunit": "^9.5", diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 89b7f1127..032771bfb 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -2767,9 +2767,7 @@ protected function _getDateTimeValue($value, $timeFormat) { } if (is_numeric($value)) { - // @codingStandardsIgnoreStart - $value = @strftime('%Y-%m-%d %H:%M:%S', $value); - // @codingStandardsIgnoreEnd + $value = PHP81_BC\strftime('%Y-%m-%d %H:%M:%S', $value); } $meridian = 'am'; $pos = strpos($value, '-'); @@ -3024,7 +3022,7 @@ protected function _generateOptions($name, $options = array()) { } else { for ($m = 1; $m <= 12; $m++) { // @codingStandardsIgnoreStart - $data[sprintf("%02s", $m)] = @strftime("%m", mktime(1, 1, 1, $m, 1, 1999)); + $data[sprintf("%02s", $m)] = PHP81_BC\strftime("%m", mktime(1, 1, 1, $m, 1, 1999)); // @codingStandardsIgnoreEnd } }