? ? ? Pending

User tests: Successful: Unsuccessful:

avatar Fedik
Fedik
18 Aug 2021

Pull Request for Issue #35204 .

Summary of Changes

Correcting CalendarField::filter to use DATE_FORMAT_FILTER_DATETIME for translated date.
Was broken somewhere after #12414

Technical note: there should be 2 string translated:
DATE_FORMAT_CALENDAR_DATETIME - used for display (uses strftime format)
DATE_FORMAT_FILTER_DATETIME - used for server side filtering (uses datetime format),

Testing Instructions

Please follow #35204

Documentation Changes Required

none

avatar Fedik Fedik - open - 18 Aug 2021
avatar Fedik Fedik - change - 18 Aug 2021
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 18 Aug 2021
Category Libraries
eceec35 18 Aug 2021 avatar Fedik phpcs
avatar Fedik Fedik - change - 18 Aug 2021
Labels Added: ?
avatar PhilETaylor PhilETaylor - test_item - 18 Aug 2021 - Tested successfully
avatar Fedik Fedik - change - 18 Aug 2021
The description was changed
avatar Fedik Fedik - edited - 18 Aug 2021
avatar Fedik Fedik - change - 18 Aug 2021
Labels Added: ?
Removed: ?
avatar infograf768
infograf768 - comment - 19 Aug 2021

Has this been tested with Jalali calendar (Persian fa-IR, only available for now as 3.x pack)?

avatar Fedik
Fedik - comment - 19 Aug 2021

I tried, it works there.
The date value is sent in "gregorian" for every language.

avatar joomdonation
joomdonation - comment - 19 Aug 2021

@Fedik We would get error with Debug Language set to Yes. Basically, in your new code, we will have to process Debug same as how we do in getInput method https://github.com/joomla/joomla-cms/blob/4.0-dev/libraries/src/Form/Field/CalendarField.php#L212-L229

If you don't mind, I want to clean up the code abit more to avoid repeating code (for calculating format in getInput and filter method):

  1. Define a new property filterFormat and remove translateFormat properly
  2. Move the logic to process translate format into setup method (so that we won't have to repeat the logic in two separate methods)
  3. Few other small cleanup

Here is the result https://github.com/joomla/joomla-cms/compare/4.0-dev...joomdonation:calendar_filter?expand=1 (to me, it is cleaner, but maybe it is just me :D

If you like that change, I made PR Fedik#9 to your branch.

If not, please handle the Debug language as I mentioned and I will test it.

avatar Fedik Fedik - change - 19 Aug 2021
Labels Added: ? ?
Removed: ?
avatar Fedik
Fedik - comment - 19 Aug 2021

well, I do not see language debug manipulation in J3,

$translateFormat = (string) $element['translateformat'];

and I do not like it ?

But if something I will tell that it is you ?

avatar Fedik Fedik - change - 20 Aug 2021
Labels Added: ? ?
Removed: ? ?
avatar joomdonation joomdonation - test_item - 20 Aug 2021 - Tested successfully
avatar joomdonation
joomdonation - comment - 20 Aug 2021

I have tested this item successfully on 567cbb0

All good now. Thanks !


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

avatar joomdonation
joomdonation - comment - 20 Aug 2021

@PhilETaylor Could you please test it again?

avatar PhilETaylor
PhilETaylor - comment - 20 Aug 2021

Im going to mark this as successful as it addresses the reported issue

However in testing I was able to break it - with insane values for the format in DATE_FORMAT_CALENDAR_DATETIME

DATE_FORMAT_CALENDAR_DATETIME="%m 2- %d     %Y %H:%M:%S"

If the date was today (08-20-2021 04:47:41) then the above format outputs 08 2- 03 2-2020 11:41:04 which is incorrect.

avatar PhilETaylor PhilETaylor - test_item - 20 Aug 2021 - Tested successfully
avatar PhilETaylor
PhilETaylor - comment - 20 Aug 2021

I have tested this item successfully on 567cbb0


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

avatar PhilETaylor
PhilETaylor - comment - 20 Aug 2021

Another insane check - on the frontend if I use

DATE_FORMAT_CALENDAR_DATETIME="%m-%d     MINE     %Y %H:%M:%S"

Then you cannot save - but again I think Im pushing the edges of what we should be supporting here.

avatar joomdonation
joomdonation - comment - 20 Aug 2021

Yes. The language file need to provider correct value for these languages item.

Actually, the error happens if users enter random string into the input instead of select a date/time from the picker, but that could be addressed in separate PR

avatar joomdonation joomdonation - change - 20 Aug 2021
Status Pending Ready to Commit
avatar joomdonation
joomdonation - comment - 20 Aug 2021

RTC


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

avatar PhilETaylor
PhilETaylor - comment - 20 Aug 2021

Actually, the error happens if users enter random string into the input instead of select a date/time from the picker

I tried that and it handled it well, by removing my rubbish and replacing it with a "now" date/time string.

avatar joomdonation
joomdonation - comment - 20 Aug 2021

I tried that and it handled it well, by removing my rubbish and replacing it with a "now" date/time string.

Ah, Yes. A happy strange that no error throws for that case. I thought there would be exception, happy to see that it does not happen. So all good :)

avatar Fedik
Fedik - comment - 20 Aug 2021

However in testing I was able to break it - with insane values for the format in DATE_FORMAT_CALENDAR_DATETIME

The date constants DATE_FORMAT_CALENDAR_DATETIME and DATE_FORMAT_FILTER_DATETIME must be in sync.

DATE_FORMAT_CALENDAR_DATETIME="%m 2- %d     %Y %H:%M:%S"
DATE_FORMAT_FILTER_DATETIME="m 2- d     Y H:i:s"

and

DATE_FORMAT_CALENDAR_DATETIME="%m-%d     MINE     %Y %H:%M:%S"
DATE_FORMAT_FILTER_DATETIME="m-d     \M\I\N\E     Y H:i:s"

This probably a legacy from transition from mootools calendar to current calendar.
It is asking for refactoring, but well, not much easy task.

avatar PhilETaylor
PhilETaylor - comment - 20 Aug 2021

No worries - like I said, I know I was pushing the extremes and this PR fixes the reported issue.

avatar Bakual
Bakual - comment - 20 Aug 2021

This probably a legacy from transition from mootools calendar to current calendar.

Yep, I know for a fact. In J3 there was no way to change that at the time ?
If the new calendar also can use the PHP Date format, then a refactoring would be welcome. You could then use the filter format string and we keep the other for B/C until J5.0.

avatar dgrammatiko
dgrammatiko - comment - 20 Aug 2021

If the new calendar also can use the PHP Date format, then a refactoring would be welcome.

@Bakual care to explain a bit further? I might contribute a new calendar based on ecmascript temporal and intl, but would be nice to know other devs preferences

avatar Fedik
Fedik - comment - 20 Aug 2021

@dgrammatiko it about using 2 diferent format at same time, currently:
strftime for calendar js https://www.php.net/manual/en/function.strftime.php for DATE_FORMAT_CALENDAR_DATETIME
datetime for calendar php https://www.php.net/manual/en/datetime.format.php for DATE_FORMAT_FILTER_DATETIME

If both will use datetime format, then it could be much simpler.
Or even something from php-intl for correct translations for a dates.

In theory ?

avatar PhilETaylor
PhilETaylor - comment - 20 Aug 2021

While all these calendar things are still fresh in your mind - maybe you all would like to review this issue from 2019 as well if you have a moment

#24417

avatar PhilETaylor
PhilETaylor - comment - 22 Aug 2021

I just had the same issue with the chinese simplified language pack, and this PR fixed that too.

avatar wilsonge wilsonge - change - 22 Aug 2021
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2021-08-22 22:25:46
Closed_By wilsonge
Labels Added: ? ? ?
Removed: ? ?
avatar wilsonge wilsonge - close - 22 Aug 2021
avatar wilsonge wilsonge - merge - 22 Aug 2021
avatar wilsonge
wilsonge - comment - 22 Aug 2021

Thanks!

Add a Comment

Login with GitHub to post a comment