Skip to content

Commit

Permalink
FormHelper migration strftime to Intl.
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilwylegala committed May 30, 2024
1 parent d68dc79 commit 4332b5f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 2 additions & 4 deletions lib/Cake/View/Helper/FormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, '-');
Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit 4332b5f

Please sign in to comment.