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

[5.2] CalendarField: changing strftime to date #44114

Merged
merged 3 commits into from
Nov 13, 2024

Conversation

Hackwar
Copy link
Member

@Hackwar Hackwar commented Sep 18, 2024

Pull Request for Issue #42790 and a lot more.

Summary of Changes

When using the calendar field without a format and without setting translateformat="true", the field tries to convert the value with strftime(), which is deprecated and throws a warning. This PR replaces strftime() with date() instead and converts the time format from strftime to date-format. To make this as compatible as possible, the conversion method has been extended to include as many conversions as possible. Since this only converts datetimes, the chance that someone is using a format with additional text besides the strftime-format is neglectable.

Testing Instructions

Actual result BEFORE applying this Pull Request

Expected result AFTER applying this Pull Request

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

@ceford
Copy link
Contributor

ceford commented Sep 19, 2024

Can you give us exact test instructions? I have forgotten what happened previously and I cannot reproduce the error in 5.2.0-beta3-dev.

@richard67
Copy link
Member

Can you give us exact test instructions? I have forgotten what happened previously and I cannot reproduce the error in 5.2.0-beta3-dev.

@ceford Maybe it can be tested as described in PR #43947 ? I haven't tried that yet.

@chmst
Copy link
Contributor

chmst commented Sep 19, 2024

I get the message only with PHP < 8.2. The patch works as described for this field, but did not test with other configurations. and not sure if this is a good solution.

Field definition in my component.

	<field
		name="date_from"
		type="calendar"
		format="%Y-%m-%d"
		showtime="false"
		label="COM_EVENT_DATE_FROM"
		description="COM_EVENT_DATE_FROM_DESC"
	/>

@ceford for a test, change the field definiton in a compoment, for example in com_content, article.xml like this or with all possible different settings:

		<field
			name="created"
			type="calendar"
			label="COM_CONTENT_FIELD_CREATED_LABEL"
		format="%Y-%m-%d"
		showtime="false"
			filter="user_utc"
		/>

and different php versions

@aberenguer78
Copy link

Solution of Chat GPT:
If your current code looks like this using strftime():

php
Copiar código
echo strftime('%Y-%m-%d %H:%M:%S', time());

You can replace it with the DateTime object or the date() function as follows:

php
Copiar código
// Using DateTime object
$date = new DateTime();
echo $date->format('Y-m-d H:i:s');

// Or using the date() function
echo date('Y-m-d H:i:s', time());

@aberenguer78
Copy link

The solution provided I do not consider a proper solution. I don't want to change the configuration of xml manifest field.
You must solve in the code as described before.

@aberenguer78
Copy link

Hi,
sorry for my message I hadn't seen the commit and the changes in code. I have tested in my local joomla web site and it's working fine now, tested succesfully
thanks

@fgsw
Copy link

fgsw commented Oct 24, 2024

@aberenguer78 Can you open https://issues.joomla.org/tracker/joomla-cms/44114 and

  • click button "Test this"
  • mark "Tested successfully"

The test will count as successfull.

@aberenguer78
Copy link

I have tested this item ✅ successfully on bc5ba11

I have replaced the files modified in Joomla core, and the deprecation errors disappear without changing any XML manifest configuration of the component.


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

@viocassel
Copy link
Contributor

I have tested this item ✅ successfully on bc5ba11


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

@richard67
Copy link
Member

RTC


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

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Nov 11, 2024
@pe7er pe7er self-assigned this Nov 13, 2024
@pe7er pe7er enabled auto-merge (squash) November 13, 2024 15:14
@pe7er pe7er merged commit 26c9f50 into joomla:5.2-dev Nov 13, 2024
3 checks passed
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Nov 13, 2024
@Quy Quy added this to the Joomla! 5.2.2 milestone Nov 13, 2024
@Hackwar Hackwar deleted the 5.2-calendar-strftime branch November 13, 2024 16:56
@pe7er
Copy link
Contributor

pe7er commented Nov 13, 2024

Thanks @Hackwar !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants