Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8.1: strftime depreceted #280

Closed
pkristian opened this issue Dec 3, 2021 · 2 comments
Closed

PHP 8.1: strftime depreceted #280

pkristian opened this issue Dec 3, 2021 · 2 comments

Comments

@pkristian
Copy link
Contributor

Version: 2.10.6

Bug Description

strftime is deprecated in PHP 8.1 and filter date could produce error.

: strftime($format, $time->format('U') + 0); // formats according to locales

Steps To Reproduce

{var $str = '2021-12-01 00:00:00'}
({$str|date:'%Y-%m-%d'})

Expected Behavior

not throwing anything

Possible Solution

add @ or replace it all together? :)

@dg
Copy link
Member

dg commented Dec 4, 2021

The solution is to use the format without % characters, i.e.: Y-m-d.

@MikyWoW
Copy link

MikyWoW commented Jan 13, 2022

Format without % using date() function which doesn´t respect locale. Correct solution is implement function IntlDateFormatter::format(). (intl extension required).

Docker:apt-get install -y libicu-dev && docker-php-ext-configure intl && docker-php-ext-install intl

https://unicode-org.github.io/icu/userguide/format_parse/datetime/#date-field-symbol-table

$date = new \DateTime();
$fmt = new \IntlDateFormatter(
            'cs_CZ',
            \IntlDateFormatter::FULL,
            \IntlDateFormatter::FULL,
            'Europe/Prague',
            \IntlDateFormatter::GREGORIAN,
            'EEEE DD. MMMM HH:mm'
);
echo $fmt->format($date);

čtvrtek 13. ledna 12:13

edit: Correct parameters in IntlDateFormatter

edit2:
Static alternative:

// DateTime need have correct timezone
date_default_timezone_set('Europe/Prague');

$date =  new \DateTime();
echo \IntlDateFormatter::formatObject($date, 'EEEE DD. MMMM HH:mm', 'cs_CZ');

@dg dg closed this as completed Jan 24, 2022
jtojnar added a commit to jtojnar/entries that referenced this issue Oct 31, 2022
PHP 8.1 deprecated strftime so the upcoming bump would complain.

nette/latte#280
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants