? Success

User tests: Successful: Unsuccessful:

avatar Bakual
Bakual
20 Sep 2016

With the current calendar we can specify the date format in the XML file. Eg "%Y-%m-%d %H:%M:%S". However that is hardcoded and the same for every language.
This PR proposes that we can set the calendar so it adjusts the format to the active language.

Summary of Changes

Introduces two new attributes showtime and translateformat for the JFormFieldCalendar:

  • translateformat: If set to true, the calendar will use a language string to determine the format. The format attribute is ignored. If false, the format attribute is used (same behaviour as today).
  • showtime: If set to true and translateformat is true, the language key DATE_FORMAT_CALENDAR_DATETIME is used, otherwise DATE_FORMAT_CALENDAR_DATE.
    Please note that this attribute is also used in the PR #11138 to specify if the calendar should show a timefield or not. Imho it makes sense to use the same attribute here.

Testing Instructions

  1. Apply PR
  2. Add the new language strings to your second language you have installed. Eg for de-DE add this to both de-DE.ini files (frontend and backend):
DATE_FORMAT_CALENDAR_DATE="%d.%m.%Y"
DATE_FORMAT_CALENDAR_DATETIME="%d.%m.%Y %H:%M:%S"
  1. Check backend article edits and watch the format changing from YYYY-MM-DD to DD.MM.YYYY if you change the language.
  2. Active the user - profile plugin and edit your profil in frontend. Check the birthday field and watch the change in format. Also this field should not show the time.

Current Limitations

  • This PR so far only changed the backend article form and the frontend profile form. If accepted it can of course be expanded to all other forms as well (just needs change in the XML).
  • I honestly don't know if this will work for all languages and possible date formats. That is something the language pack creators have to test when creating the language strings.

Documentation Changes Required

New attributes need to be added to https://docs.joomla.org/Calendar_form_field_type

avatar Bakual Bakual - open - 20 Sep 2016
avatar Bakual Bakual - change - 20 Sep 2016
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 20 Sep 2016
Labels Added: ? ?
avatar joomla-cms-bot joomla-cms-bot - change - 20 Sep 2016
Category Administration Components Language & Strings Libraries Plugins Front End
avatar jeckodevelopment jeckodevelopment - change - 20 Sep 2016
Labels Added: ?
avatar ot2sen ot2sen - test_item - 20 Sep 2016 - Tested successfully
avatar ot2sen
ot2sen - comment - 20 Sep 2016

I have tested this item ✅ successfully on f1ba93b

Works as described backend and front.

Note: The descriptive label for the front birthday field would also need to be adjusted accordingly in the language files. Tested with German de-DE and the text above the birthday entry field says "Das Geburtsdatum muss im Format Jahr-Monat-Tag (z. B. 1980-12-01) eingegeben werden." which is opposite to the new changed format added in de-DE inis.


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

avatar Bakual
Bakual - comment - 20 Sep 2016

The descriptive label for the front birthday field would also need to be adjusted accordingly in the language files.

True enough, the language files need to be updated. However not sure what we can do with this PR since the english string is actually fine. Probably just needs a notice in the translators forum.

avatar ot2sen
ot2sen - comment - 20 Sep 2016

Agree, simply something for the language pack creators to have attention to in the case they use other format than specified en-GB.

avatar infograf768
infograf768 - comment - 20 Sep 2016

?
Indeed, this should be explained to TTs.

avatar infograf768 infograf768 - test_item - 20 Sep 2016 - Tested successfully
avatar infograf768
infograf768 - comment - 20 Sep 2016

I have tested this item ✅ successfully on f1ba93b


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

avatar zero-24 zero-24 - change - 20 Sep 2016
Status Pending Ready to Commit
avatar zero-24
zero-24 - comment - 20 Sep 2016

RTC @Bakual please sync to staging (there should be a button) to fix the travis problems :)


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

avatar joomla-cms-bot joomla-cms-bot - change - 20 Sep 2016
Labels Added: ?
avatar infograf768
infograf768 - comment - 20 Sep 2016

@Bakual
I suggest to add a comment before the following langstring in /administrator/language/en-GB/en-GB.plg_user_profile.ini, with no empty line before and after.
i.e.:

; Adapt the following string to the format you entered in the 'DATE_FORMAT_CALENDAR_DATE' 
PLG_USER_PROFILE_SPACER_DOB="The date of birth entered should use the format Year-Month-Day, ie 0000-00-00"
avatar joomla-cms-bot joomla-cms-bot - change - 20 Sep 2016
Labels Added: ?
avatar Bakual
Bakual - comment - 20 Sep 2016

Rebased on 3.7.x branch and added comment.

avatar Minei3oat Minei3oat - test_item - 20 Sep 2016 - Tested unsuccessfully
avatar Minei3oat
Minei3oat - comment - 20 Sep 2016

I have tested this item ? unsuccessfully on 639dac8

DateTime::__construct(): Failed to parse time string (09.20.2016 20:30:16) at position 8 (1): Unexpected character

Format: %m.%d.%Y %H:%M:%S

There must be a conversion from the selected format after submitting the form or there are only a few formats allowed: http://php.net/manual/en/datetime.formats.php


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

avatar zero-24 zero-24 - change - 20 Sep 2016
Labels Removed: ?
avatar Bakual
Bakual - comment - 20 Sep 2016

I had a look at that page earlier and couldn't figure out which formats are accepted and which not. I found it quite confusing. But I found out that "5th october 2016" actually works with our calendar field ?

I have a look if we can use a server side validation rule to improve the possible formats.

avatar joomla-cms-bot joomla-cms-bot - change - 20 Sep 2016
Labels Added: ?
avatar Minei3oat
Minei3oat - comment - 20 Sep 2016

I think the formats in the tables after the first table are accepted ? (The examples are good).

avatar Bakual
Bakual - comment - 22 Sep 2016

I had a look at server side JFormRules. Unfortunately they can't change the values, they just can test them and return true/false. Or at least I couldn't figure out a way.
That means each extension would have to check the dates and adjust the format in their code, which isn't ideal as it means duplicated code all over the place.

Does someone know a way to "post process" a formfields value on a library level (outside the extension)? I'm not aware of it but I may miss something.

avatar Bakual
Bakual - comment - 22 Sep 2016

@Minei3oat Can you test again? I make now use of the already existing filters user_utc and server_utc. They will now check the date and convert it according to the specified format.
Unfortunately we can't parse the date using the %Y-%m-%d format spec. The function strptime which would do exactly that doesn't exist on Windows systems. So I had to use date_parse_from_format which uses the Y-m-d spec. That means two additional language strings.

On a side note if someone wonders: date_create_from_format doesn't work because when the format is only partial met (eg no seconds entered), it will fail.

avatar Minei3oat Minei3oat - test_item - 22 Sep 2016 - Tested successfully
avatar Minei3oat
Minei3oat - comment - 22 Sep 2016

I have tested this item ✅ successfully on 474b7de


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

avatar infograf768
infograf768 - comment - 23 Sep 2016

On a side note if someone wonders: date_create_from_format doesn't work because when the format is only partial met (eg no seconds entered), it will fail.

Do you mean that, for a birthday date one would have to enter hour minutes seconds or that one could still do only d-m-Y and IF using hours, making sure hour AND minutes AND seconds should be entered?

avatar Bakual
Bakual - comment - 23 Sep 2016

Do you mean that, for a birthday date one would have to enter hour minutes seconds or that one could still do only d-m-Y and IF using hours, making sure hour AND minutes AND seconds should be entered?

No, the current code works when you enter only a partial date/time value. I'm not using date_create_from_format in the code. I just wrote it because it would seem the simplest and obvious function to use, but as I wrote it fails in our case.
So to be completely clear: For the birthday date where showtime is false, you don't have to specify the time at all. For the other calendar fields where showtimeis true, you can omit part of the time. It will be replaced with 0 then.

avatar Bakual
Bakual - comment - 30 Sep 2016

Rebased so hopefully the unrelated Travis error is now gone.

avatar rdeutz rdeutz - change - 1 Oct 2016
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2016-10-01 07:41:01
Closed_By rdeutz
avatar rdeutz rdeutz - close - 1 Oct 2016
avatar rdeutz rdeutz - merge - 1 Oct 2016
avatar zero-24 zero-24 - close - 1 Oct 2016
avatar zero-24 zero-24 - change - 3 Oct 2016
Labels Removed: ?
avatar zero-24
zero-24 - comment - 18 Mar 2017

The new attributes are added here: https://docs.joomla.org/Calendar_form_field_type please coerrer any errors there. Thanks ?

avatar Bakual
Bakual - comment - 18 Mar 2017

Perfect, thanks a lot for taking care of it!

Add a Comment

Login with GitHub to post a comment