? PHP 8.x ? Pending

User tests: Successful: Unsuccessful:

avatar joomdonation
joomdonation
16 Feb 2023

Pull Request for Issue # .

Summary of Changes

On PHP 8.1+, we will see deprecated warning like below when you use HTMLHelper calendar method

Deprecated : Function strftime() is deprecated in [ROOT]\libraries\src\HTML\HTMLHelper.php on line XXXX

This PR attempts to solve it by converting some of the most widely used format parameters uses by strftime() function to the DateTime format use by DateTime class. Then use DateTimeImmutable class to format the input value instead of using strftime() function.

The supported formats which will be converted automatically are: %Y, %m, %d, %H, %M, %S.

It does not solve the issue for every cases, but hopefully, most of developers just use these supported formats and won't have to update their code to address this deprecated warning.

Testing Instructions

  1. Use Joomla 4 on PHP 8.1 or PHP 8.2
  2. Open the file , paste the following lines of code somewhere administrator/templates/atum/index.php (I attempt to test the function with different combination of the supported formats)
$data = [
  '%Y-%m-%d' => '2023-12-20',
  '%d-%m-%Y' => '2023-12-20',
  '%m-%d-%Y' => '2023-12-20',
  '%Y-%m-%d %H:%M:%S' => '2023-12-20 13:20:00',
  '%d-%m-%Y %H:%M:%S' => '2023-12-20 13:20:00',
  '%m-%d-%Y %H:%M:%S' => '2023-12-20 13:20:00',
  '%Y-%m-%d %H:%M' => '2023-12-20 13:20',
  '%d-%m-%Y %H:%M' => '2023-12-20 13:20',
  '%m-%d-%Y %H:%M' => '2023-12-20 13:20',
];

$name = 'test_calendar';
$count = 0;

foreach ($data as $format => $value) {
    echo HTMLHelper::_('calendar', $value, $name . '_' . $count, $name . '_' . $count, $format) . '<br />';
    $count++;
}

Actual result BEFORE applying this Pull Request

You will see ton of deprecated warnings

Expected result AFTER applying this Pull Request

No warnings anymore, the calendar inputs are displayed with the right date.

Link to documentations

Please select:

  • No documentation changes for docs.joomla.org needed
  • No documentation changes for manual.joomla.org needed
avatar joomla-cms-bot joomla-cms-bot - change - 16 Feb 2023
Category Libraries
avatar joomdonation joomdonation - open - 16 Feb 2023
avatar joomdonation joomdonation - change - 16 Feb 2023
Status New Pending
avatar alikon alikon - test_item - 16 Feb 2023 - Tested successfully
avatar alikon
alikon - comment - 16 Feb 2023

I have tested this item successfully on 342cf1f


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39869.

avatar alikon
alikon - comment - 16 Feb 2023

after pr
image

avatar viocassel viocassel - test_item - 16 Feb 2023 - Tested successfully
avatar viocassel
viocassel - comment - 16 Feb 2023

I have tested this item successfully on 342cf1f


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39869.

avatar Quy Quy - change - 16 Feb 2023
Status Pending Ready to Commit
Labels Added: ?
avatar Quy
Quy - comment - 16 Feb 2023

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39869.

avatar Quy Quy - change - 23 Feb 2023
Labels Added: ? PHP 8.x
avatar fancyFranci fancyFranci - change - 24 Feb 2023
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2023-02-24 23:04:46
Closed_By fancyFranci
avatar fancyFranci fancyFranci - close - 24 Feb 2023
avatar fancyFranci fancyFranci - merge - 24 Feb 2023
avatar fancyFranci
fancyFranci - comment - 24 Feb 2023

Nice! Thank you!

Add a Comment

Login with GitHub to post a comment