? ? PHP 8.x ? Pending

User tests: Successful: Unsuccessful:

avatar laoneo
laoneo
20 Mar 2022

Pull Request for Issue #34952 and takeover from #36395.

Summary of Changes

The calendar field uses the strftime to format a date. This function got deprecated in PHP 8.1 and will be removed in 9. This pr uses the widely accepted date function.
There are probably edge cases for format conversion, which are not covered by this pr, but can be added later.

Full credit goes to @PhilETaylor, I was just taking it over and made some small modifications.

Testing Instructions

  • Create a new article in the back end
  • Click on the publishing tab

Actual result BEFORE applying this Pull Request

The following message is displayed:
Deprecated: Function strftime() is deprecated in /libraries/src/Form/Field/CalendarField.php on line 277

Expected result AFTER applying this Pull Request

No error message.

avatar laoneo laoneo - open - 20 Mar 2022
avatar laoneo laoneo - change - 20 Mar 2022
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 20 Mar 2022
Category Libraries Unit Tests
avatar laoneo laoneo - change - 20 Mar 2022
The description was changed
avatar laoneo laoneo - edited - 20 Mar 2022
avatar tecpromotion
tecpromotion - comment - 20 Mar 2022

I have tested this item successfully on fca7309


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

avatar tecpromotion tecpromotion - test_item - 20 Mar 2022 - Tested successfully
avatar brianteeman
brianteeman - comment - 20 Mar 2022

Surely this has to go in 4.2

avatar BPBlueprint
BPBlueprint - comment - 22 Mar 2022

I have tested this item successfully on fca7309


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

avatar BPBlueprint BPBlueprint - test_item - 22 Mar 2022 - Tested successfully
avatar laoneo laoneo - change - 22 Mar 2022
Labels Added: ? ? ?
avatar laoneo
laoneo - comment - 22 Mar 2022

rtc


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

avatar laoneo laoneo - change - 22 Mar 2022
Status Pending Ready to Commit
avatar laoneo
laoneo - comment - 22 Mar 2022

rtc


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

avatar MacJoom
MacJoom - comment - 22 Mar 2022

I have tested this item successfully on fca7309


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

avatar MacJoom MacJoom - test_item - 22 Mar 2022 - Tested successfully
avatar bembelimen
bembelimen - comment - 24 Mar 2022

Surely this has to go in 4.2

Yes, or 5.0

avatar bembelimen bembelimen - change - 24 Mar 2022
Labels Added: ? PHP 8.x
Removed: ?
avatar laoneo
laoneo - comment - 25 Mar 2022

If this has to go into 5, then Joomla 4 will never be able to run on PHP 9. If it has to go into 4.2, then I suggest an alternative parameter where extension developers can define a format in normal PHP date format. Something like date_format. So the tag would look like:

<field
	name="begin"
	type="calendar"
	label="COM_BANNERS_BEGIN_LABEL"
	hint="COM_BANNERS_BEGIN_HINT"
	format="%Y-%m-%d"
	date_format="Y-m-d"
	filter="user_utc"
/>

Extension developers can then still use the normal format parameter to keep backwards compatibility with Joomla 3.

What do you guys think?

avatar brianteeman
brianteeman - comment - 25 Mar 2022

If you go down the route of the extra date_format then you should also update all date fields in joomla so that they are using the new way and nothing in core is using the old and presumably deprecated method.

@nibra See I think I understand now your comments in the RFC

avatar joomdonation
joomdonation - comment - 25 Mar 2022

Actually, we can use a hidden parameter filterFormat

. It is not documented, but used on all of our calendar form fields when translateformat="true" , see https://github.com/joomla/joomla-cms/blob/4.1-dev/libraries/src/Form/Field/CalendarField.php#L207

So Calendar Form fields from core will still work as how it is. For third party extensions, we can just add filterFormat attribute with the right value and it is working OK, too. If the attribute is not available, we can use the code to convert format like how we are doing in this PR (maybe just for PHP >= 8.1.0)

avatar laoneo
laoneo - comment - 25 Mar 2022

@joomdonation can you make an alternative pr with the filterFormat? But please make it compatible with all PHP versions.

avatar joomdonation
joomdonation - comment - 25 Mar 2022

@laoneo If it is OK to make PR without writing unit test, I will give it a try (I don't know how to write unit tests at the moment). Also, I will have to borrow the code of strftimeFormatToDateFormat method in this PR.

avatar laoneo
laoneo - comment - 25 Mar 2022

Sure

avatar laoneo laoneo - change - 25 Mar 2022
Status Ready to Commit Closed
Closed_Date 0000-00-00 00:00:00 2022-03-25 16:19:40
Closed_By laoneo
Labels Added: ?
Removed: ?
avatar laoneo laoneo - close - 25 Mar 2022

Add a Comment

Login with GitHub to post a comment