User tests: Successful: Unsuccessful:
Pull Request for Issue # .
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.
$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++;
}
You will see ton of deprecated warnings
No warnings anymore, the calendar inputs are displayed with the right date.
Please select:
Category | ⇒ | Libraries |
Status | New | ⇒ | Pending |
I have tested this item
Status | Pending | ⇒ | Ready to Commit |
Labels |
Added:
?
|
RTC
Labels |
Added:
?
PHP 8.x
|
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 |
Nice! Thank you!
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.