? ? ? Pending

User tests: Successful: Unsuccessful:

avatar PhilETaylor
PhilETaylor
28 Dec 2021

Summary of Changes

@Bakual @dgrammatiko

strftime is deprecated, Joomla Core only uses it (AFAIK) for the frontend calendars for the Smart Search Filters (not enabled by default either).

This PR provides a test case that can be run before the code change, and you can see it passes.

This PR provides a test case that can be run after the code change (The removal of strftime calls), and you can see it passes.

This PR is a light touch approach, simply converting strftime format to DateTimeInterface format using a simple mapping table thanks to @relipse on StackOverflow. Its not perfect, as the comments point out, but its the best that can be expected - especially as its only used in Core Joomla a few places, and might only effect 3PD more than Joomla Core. The formats that are not mapped, and thus dont work, are not the kind of formats you would use in a calendar field anyway (Like, why would you select a Date and then only show the month name?! you wouldn't)...

Testing Instructions

You can test in any PHP version.
In Joomla 4 admin -> Smart Search -> Options -> Enable Date Filters
Create Menu item to the Smart Search
Visit frontend menu item for Smart Search, Click Advanced Search

and/or:

Any 3PD that uses the calendar field is invited to test this at a PHP code level implementing the calendar field with

HTMLHelper::calendar('1978-03-08 06:12:12', 'testName', 'testId', '%Y-%m-%d', []);

Actual result BEFORE applying this Pull Request

Calendar works fine, and after selecting a date, the formatted date is shown in the text box (for Joomla Core this is %Y-%m-%d like 1978-03-08 by default)

Expected result AFTER applying this Pull Request

Calendar works fine, and after selecting a date, the formatted date is shown in the text box (for Joomla Core this is %Y-%m-%d like 1978-03-08 by default)

Note

Im aware there is a CalendarField.php call with strftime in it, that will be done next.

avatar PhilETaylor PhilETaylor - open - 28 Dec 2021
avatar PhilETaylor PhilETaylor - change - 28 Dec 2021
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 28 Dec 2021
Category Libraries Unit Tests
avatar PhilETaylor PhilETaylor - change - 28 Dec 2021
The description was changed
avatar PhilETaylor PhilETaylor - edited - 28 Dec 2021
avatar PhilETaylor PhilETaylor - change - 28 Dec 2021
The description was changed
avatar PhilETaylor PhilETaylor - edited - 28 Dec 2021
avatar PhilETaylor PhilETaylor - change - 28 Dec 2021
Labels Added: ? ?
d201209 28 Dec 2021 avatar PhilETaylor cs
avatar Bakual
Bakual - comment - 28 Dec 2021

We had a proposal to do an automatic conversion of the strftime to Date format in the past. It didn't work well.
I'm not a fan of doing such automatic conversion, but it will be better than nothing.
Main thing to do is imho to rewrite the calendar so it doesn't use the strftime format anymore (if it still does). And then the calendar formfield can be rewritten to only use the Date formatstring (that one already exists in the language pack).

avatar PhilETaylor
PhilETaylor - comment - 28 Dec 2021

We had a proposal to do an automatic conversion of the strftime to Date format in the past. It didn't work well.

Ive not seen it. Just because it failed in the past doesn't mean this attempt will fail too.

I'm not a fan of doing such automatic conversion, but it will be better than nothing.

There is no other way. strftime is going to be removed. If you want backward compatibility then there is no other way.

Main thing to do is imho to rewrite the calendar so it doesn't use the strftime format anymore (if it still does).

Out of scope of this PR. I will not be rewriting the calendar. It still does use strftime format. Rewriting the calendar will not be backward compatible.

This PR is backward compatible and provides a useable Unit Test that you can add as many unit test cases to throw at its implementation change to prove that it works.

avatar dgrammatiko
dgrammatiko - comment - 28 Dec 2021

Like, why would you select a Date and then only show the month name?! you wouldn't

Famous last words...

FWIW if @Bakual is ok I'm more than happy with the changes

avatar PhilETaylor
PhilETaylor - comment - 28 Dec 2021

@dgrammatiko looking forward to your rewrite that for Joomla 5 that allows us to break b/c and use PHP dates ;-)

avatar brianteeman
brianteeman - comment - 28 Dec 2021

@PhilETaylor only when php dates support all non gregorian calendars

avatar PhilETaylor
PhilETaylor - comment - 28 Dec 2021

Famous last words...

The only strftime formats NOT mapped are

%U Week number of the given year, starting with the first Sunday as the first week 13 (for the 13th full week of the year)
%V ISO-8601:1988 week number of the given year, starting with the first week of the year with at least 4 weekdays, with Monday being the start of the week 01 through 53 (where 53 accounts for an overlapping week)
%C Two digit representation of the century (year divided by 100, truncated to an integer) 19 for the 20th Century
%g Two digit representation of the year going by ISO-8601:1988 standards (see %V) Example: 09 for the week of January 6, 2009
%G The full four-digit version of %g Example: 2008 for the week of January 3, 2009
avatar PhilETaylor
PhilETaylor - comment - 28 Dec 2021

And if you are really scared that 3PD might need those 5 representations, then we can add them... just seems a lot of work for not a lot of people...

avatar dgrammatiko
dgrammatiko - comment - 28 Dec 2021

looking forward to your rewrite that for Joomla 5 that allows us to break b/c and use PHP dates ;-)

As I wrote in the other issue 2022 will be the year that all browsers will roll temporal: https://github.com/tc39/proposal-temporal (implemented behind a flag already in a few). I don't know if I will be the one that will rewrite the calendar but once that piece of code is available (actually it is right now with a polyfill...) the calendars will be way easier than the current thing...

avatar PhilETaylor
PhilETaylor - comment - 28 Dec 2021

But - and Im sorry to bang on about it again - The rewrite of the calendar is a BACKWARD INCOMPATIBLE CHANGE and therefore "for the future" and not a solution to the current issue that strftime is now deprecated.

Therefore we need a plan for Joomla 4 (And Joomla 3 if the plan is to support > PHP 8.1 in Joomla 3).

I propose this. Along with a Unit test that can be abused to prove its worth.

avatar PhilETaylor
PhilETaylor - comment - 28 Dec 2021

Drone failures unrelated to the content of this PR.

avatar Fedik
Fedik - comment - 29 Dec 2021

Current PR is okay as temporary solution.

only when php dates support all non gregorian calendars

@brianteeman it can, try this:

$formatter = new \IntlDateFormatter('fa_IR', \IntlDateFormatter::LONG, \IntlDateFormatter::NONE);
echo $formatter->format(time());

It just not easy to integrate to the api we have. It should be something new (kind of calendar2 field).

For proper date format we need to think about PHP Intl date formater for server side and "temporal js" for client side.
They both based on ICU (if I right understood).
They will have common pattern format, but different from date(), strftime(). https://unicode-org.github.io/icu/userguide/format_parse/datetime/
For general use should be enough default patterns SHORT, MEDIUM, LONG.

And with it we should drop the translations for patterns in the inputs, it a horror.

avatar dgrammatiko
dgrammatiko - comment - 29 Dec 2021

For proper date format we need to think about PHP Intl date formater for server side and "temporal js" for client side.

YES, I totally agree here.

A (probably radical) idea: PHP should only (by default) deal ONLY with the SQL format (also the JS part should also return SQL formatted datetime string). That would simplify immensely the code. A quick explanation: the PHP should NOT be used to directly handle input from the UI (that's the JS's part), thus handling only one default format is totally fine.

avatar PhilETaylor
PhilETaylor - comment - 29 Dec 2021

Current PR is okay as temporary solution.

Alexa, define "temporary" -> for the whole of the Joomla 3 and 4 series and until such time as the calendar can be refactored. Possibly in 2-10 years time.

So we are all in agreement that this needs to be done for PHP 8.1+ compatibility, and doing it the way this PR does is acceptable, despite its small limitations, should not impact the real world, therefore if we can get some actual Human Tests marked we can get this one merged. More talk about "the future" of Calendar will just derail this PR further and is out of scope of this PR.

I'll try to back port this to the CalendarField.php in the libraries sometime today.

89fd99c 29 Dec 2021 avatar PhilETaylor docs
avatar PhilETaylor PhilETaylor - change - 30 Dec 2021
Labels Added: ?
avatar Fedik
Fedik - comment - 2 Jan 2022

It seems works, on quick test,
You also have to update it here:

$this->value = strftime($this->format, strtotime($this->value));

avatar PhilETaylor
PhilETaylor - comment - 2 Jan 2022

You also have to update it here

Like I have said at least twice. But I had to ensure there was buy in to the solution before wasting my time.

avatar PhilETaylor PhilETaylor - change - 6 Mar 2022
Labels Added: ?
Removed: ?
avatar PhilETaylor PhilETaylor - change - 7 Mar 2022
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2022-03-07 18:34:16
Closed_By PhilETaylor
avatar PhilETaylor PhilETaylor - close - 7 Mar 2022

Add a Comment

Login with GitHub to post a comment