Problem/Motivation
In #1802278: Add a Date component to core, we added support for the IntlDateFormatter class, which was added in PHP 5.3. This class provides locale-aware date formatting for PHP dates. When a Drupal site is running PHP is compiled with INTL support (http://ca2.php.net/manual/en/intl.installation.php), DrupalDateTime::format() attempts to automatically switch to IntlDateFormatter instead of the longstanding date_format()
used in Drupal 7 and before.
We use the INTL date formatter if you have a default country set - which will be the majority of sites. If you leave this unset in the installer or use drush and don't explicitly set this, then we use PHP date formatting (how Drupal 7 and older worked).
The INTL/PHP date switching is not well-tested and has numerous bugs that will affect a site with INTL support:
- If you configure all your data formats and then set a default country or unset the default country all your formats will change. When configuring a date format you only get to set up the currently active format.
- Currently, only PHP formats can be translated. The INTL class does handle some forms of translation, but we've still removed the ability to have different Drupal date formats depending on translation.
- f you have a view with a custom_date_format then this will break if you switch.
- It is difficult to provide a migration path for the switch from PHP to INTL date format
Furthermore the move from PHP date format to INTL is interesting in terms of migration, and custom date formats are currently not migrated for this reason. From the Known issues with the Drupal 6 -> 8 migrate path:Only the default, short, medium and long formats are migrated. All other formats default to the fallback format and need to be reconfigured after migration.
Proposed resolution
Remove the automatic switching to INTL dates and consistently use the PHP date format.
Remaining tasks
Patch is RTBC.
The following issues may be resolved by this patch:
- #2031183: Improve test coverage for node authored on widget
- #2204207: Missing format field when translating a date format using php-intl.
User interface changes
Before
After
API changes
Yes. (List here.)
Comment | File | Size | Author |
---|---|---|---|
#28 | DateFormatBefore.png | 51.38 KB | Gábor Hojtsy |
#28 | DateFormatAfter.png | 42.97 KB | Gábor Hojtsy |
#23 | 2276183.23.patch | 51.75 KB | alexpott |
#23 | 19-23-interdiff.txt | 330 bytes | alexpott |
#19 | 2276183.19.patch | 51.32 KB | alexpott |
Comments
Comment #1
alexpottComment #2
alexpottphp-intl is not ubiquitous in php (my bad). So only option 2 is available. Updated summary.
Comment #3
alexpott#2031183: Improve test coverage for node authored on widget is more evidence we've got a problem.
Comment #4
chx CreditAttribution: chx commentedComment #5
xjmI don't understand what the bug is here. I think it is somewhere in this paragraph:
I see 3-4 separate possible bugs in this paragraph:
Why wouldn't my date formats change based on the location? Are you saying that user-defined data is somehow lost? Can you provide a specific example to illustrate the problem?
So, I get that I might want to have my date format as 5-29-2014 for one translation, and 29.05.2014 for another, and 30th of Rajab, 1435 A.H. for another. Are you saying this is not possible presently? Is this a regression from D7?
Break how? Can you provide steps to reproduce?
Furthermore the move from PHP date format to INTL is interesting in terms of migration. One of the known issues for migrate is that custom date formats are not migrated (and there is no plan to fix this).
Okay, but interesting how? The link is not a bug report; it says:
Also, it's not clear to me why this must block release and the beta. What are the implications if this doesn't get done? What are the implications of resolving it after beta? Could it be resolved in contrib, or in 8.1.0? Is it worth stopping everyone from using Drupal 8 to make the change here?
Comment #6
Gábor Hojtsy@xjm: yeah date formats are separate per language in Drupal 7, so date formats not translatable is a regression. Also PHP formats ARE translatable in Drupal 8 so intl formats not being so is pretty inconsistent.
When we have been doing the date translation, we could not figure out how/when would intl be ever used and it seemed like it may be dead code but we did not follow up with that... So good find and sorry for not bringing this up there :/
Comment #7
alexpottThis blocks beta because making the intl date format transalatable involves schema change and if we suddenly make all default formats have both PHP and INTL formats then we have no upgrade path. I'm changing this to a meta to track these issues and leaving at beta blocking since the fixes to these will involve config schema changes, views config changes, and maybe significant API changes.
Comment #8
alexpottxpost
Comment #9
alexpottThinking about it we could also remove INTL support from core.
From the issue that added it #1802278: Add a Date component to core
Well as noted in #2031183: Improve test coverage for node authored on widget we have a significant test deficit if using INTL so whilst I agree it would be "nice" it certainly is not mandatory. And we could try to introduce properly in 8.1 or 9.
Comment #10
alexpottSo let's remove it and not have the headache of trying to support and switch between two different ways of formatting dates.
Comment #11
alexpottThere's more we can remove
Comment #12
catchThis seems like a good plan. We can look at adding back the feature in a later release as Alex points out in #9.
Re-titling.
Comment #13
xjmI think this sounds like a better direction, especially based on @Gábor Hojtsy's comment. So removing it would potentially resolve all four of these bugs? Thanks @alexpott.
Comment #14
alexpottI've talked to @Gábor Hojtsy, @chx, @Berdir in IRC /gchat and no one is clear on the advantages of supporting two ways of formatting dates in core.
In order to support INTL date formatting in core we need to do a lot of work for no obvious gain:
Therefore +1 on repurposing this issue to remove INTL date formatting support.
Comment #15
xjmShould we file a postponed followup to add it back when it works (maybe minor version target or against 9.x)?
Edit: I did not upload that file; d.o is being weird.
Comment #17
Gábor HojtsyTotally agree removing it is better.
One of the definite problems of intl support is it uses wildly different date formatting patterns, so that eg. admins need to understand that in intl dd means two digit day, d means no leading zero, in PHP that is d and j. So depending on what you configure, you need to use totally different background info, and the switch was never apparent. This was even worse integrating with translation because the config form only showed one type but the translation form would have needed to support both.
Comment #19
alexpottFixed the test fails
Comment #20
Gábor HojtsyHere are two kicks at the old code and one suggestion for improvement.
This is one of the many problems of intl. It would use the only country Drupal knows about -- your default country -- to format all dates. So you would end up with nonsensical combinations like en_NL, it_NL, de_NL, etc. for a site in the Netherlands.
Not even the PHP manual. :P
I think we just want to say 'Date format' here now? No need to qualify.
Comment #21
alexpott3. Well it still is a PHP date format string :)
Comment #22
Gábor HojtsyWell, my point is it does not serve to give "any new info" and is technical. The form element for the date_format type already links the proper docs and previews the format with an actual date. Not a big issue though if we want to keep the label as-is.
Comment #23
alexpottSure np
Comment #24
xjmComment #25
xjmComment #26
xjmComment #27
xjmComment #28
Gábor HojtsyTo illustrate the effect of the patch to the translate form. BEFORE the patch you have a list of date formats but intl is not supported in translation, so you only get the PHP format in a fieldset:
AFTER the patch, it says 'Date format'. I made it apparent where it used to say 'PHP date format' :D
It would probably be fine to remove "Date format" from the "Date format label" but that is not in scope of this issue. The help text for the field guides the user to the right docs already.
Comment #29
Gábor HojtsyThe patch looks very good. I cannot vouch for whether this covers 100% of references, but not sure how it is possible to figure out, we will see.
Comment #30
xjmThanks for the screenshots @Gábor Hojtsy.
A quick grep to check some possible references:
I don't think any of those are related, so the patch looks good to me as well.
Comment #31
xjmI added a change record draft:
https://drupal.org/node/2276461
Comment #32
Gábor HojtsyYeah transliteration is totally unrelated.
Comment #33
xjmComment #34
xjmI think #2031183: Improve test coverage for node authored on widget and #2204207: Missing format field when translating a date format using php-intl. can also be marked as duplicates of this? Do we need to test that those issues are resolved with this patch applied? Edit: I'm not sure about #2031183: Improve test coverage for node authored on widget.
Comment #35
xjmComment #36
catchLet's do this. At least it will unblock #2031183: Improve test coverage for node authored on widget which is the 11th oldest critical bug in 8.x at the moment.
Can always add it back in a non-broken way.
Committed/pushed to 8.x, thanks!
Comment #38
Gábor HojtsyYay! Thanks!
Comment #39
xjmPublished the CR.