Problem/Motivation
Drupal uses the following fallback values for date formats.
variable_get('date_format_short', 'm/d/Y - H:i');
variable_get('date_format_medium', 'D, m/d/Y - H:i');
variable_get('date_format_long', 'l, F j, Y - H:i');
But in Date and time types settings page (/admin/config/regional/date-time), the following formats are selected as the defauts if the variables are not set.
short: Y-m-d H:i
medium: D, Y-m-d H:i
(There is no problem with the long format.)
Proposed resolution
Change the order of selectbox options to show the fallback values as default.
Remaining tasks
Review the patch.
User interface changes
None. Only the order of selectbox of date formarts is changed.
API changes
None.
Data model changes
None.
Original report by wavesailor
/admin/reports/dblog does not display the results using the correct date format specified for the site
I have the short date specified as
2012-10-19 16:07
but /admin/reports/dblog displays the results as:
10/19/2012 - 16:07
Comment | File | Size | Author |
---|---|---|---|
#13 | drupal-default-date-format-1817748-13.patch | 3.19 KB | markpavlitski |
#13 | drupal-default-date-format-1817748-13-test-only.patch | 1.87 KB | markpavlitski |
#5 | 1817748-date-and-time-settings.png | 15.07 KB | markpavlitski |
#5 | 1817748-dblog.png | 5.79 KB | markpavlitski |
Comments
Comment #1
tim.plunkettThanks for the bug report!
It will need to be fixed in D8 first.
Comment #2
marcingy CreditAttribution: marcingy commenteddblog uses in d7
Not the short date, so if you change the long date does what is displayed change?
Comment #3
wavesailor CreditAttribution: wavesailor commentedMy long date is specified as:
but /admin/reports/dblog displays the results as:
Comment #4
wavesailor CreditAttribution: wavesailor commentedComment #5
markpavlitski CreditAttribution: markpavlitski commentedThe long date format is used on the watchdog event details page. The short format is used on the Recent log messages page (the overview).
From
dblog_overview()
:The issue occurs for both medium and short timestamps, and is caused by a mismatch between the way
format_date()
works out the format to use and the date format options listed on the Date and time settings page (from system.module).format_date()
uses a variable_get() to load the format, with a default value specified. The settings page loads all available formats usinghook_date_formats()
and picks the first one if none are set. Both short and medium formats have a different first date (provided bysystem_date_formats()
than the default value given tovariable_get()
.See attached screenshots of the dblog report and system settings page showing the different defaults (this is a vanilla D7 install using latest 7.x head).
This patch ensures the default formats match by re-ordering the dates listed in
system_date_formats()
. Not that this will not change the formats in use on the site.We could change the default values given to
variable_get()
instead, but this would change/break existing sites which use the default formats.This issue doesn't affect D8 due to the new date/time system.
Comment #6
dawehnerI guess even for 7.x we have to adds tests.
Comment #7
markpavlitski CreditAttribution: markpavlitski at Investis Digital commentedOK, test added.
Comment #9
markpavlitski CreditAttribution: markpavlitski at Investis Digital commentedI've amended the patch to be more explicit when checking the date config page.
Comment #12
hgoto CreditAttribution: hgoto as a volunteer and at Studio Umi commentedThe patch code #9 looks good to me. As for the test, the test failed because the test case enabled Locale module. Locale module hides this bug, I believe.
1.
DateTimeFunctionalTest
enables Locale module:We should create a new test class with Locale module disabled to verify this patch, I think.
2.
We may use
DrupalWebTestCase::assertOptionSelected()
here.https://api.drupal.org/api/drupal/modules%21simpletest%21drupal_web_test...
Comment #13
markpavlitski CreditAttribution: markpavlitski at Investis Digital commentedThanks @hgoto. I spent so long looking for an alternative to xpath!
Comment #15
hgoto CreditAttribution: hgoto as a volunteer commentedNow we are targeting the date and time setting page rather than the dblog page. Let's update the issue title and summary.
Comment #16
hgoto CreditAttribution: hgoto as a volunteer commentedThank you, markpavlitski. I tested the patch #13 manually and confirmed it fixed the issue.
I think it's OK to move this to RTBC but I'd like someone else to review this to be sure :)
Comment #17
hgoto CreditAttribution: hgoto as a volunteer commentedComment #18
Sophie.SKWorks nicely. My only thought is the default date should be a universal one, ie Y-m-d, rather than a regional one, m/d/Y. But the patch that's here applies cleanly and works, so marking as RTBC.
Comment #19
markpavlitski CreditAttribution: markpavlitski at Investis Digital commented@Sophie.SK - thanks!
The reason for leaving the North American default format as-is is to ensure that existing sites aren't impacted by the change. Possibly a follow-up issue could try to address that?
Comment #20
Sophie.SK@markpavlitski That makes sense. A follow-up issue might be useful, but I guess it's going to be a super-low priority one if it's only D7 affected.
Comment #21
Fabianx CreditAttribution: Fabianx as a volunteer commentedMarking for commit, nice work @all! :)
Comment #22
markpavlitski CreditAttribution: markpavlitski at Deeson commentedThanks @Fabianx! This issue has been bugging me for ages!
Comment #23
stefan.r CreditAttribution: stefan.r commentedLooks good to me as well, assigning to David for final review
Comment #24
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedCommitted to 7.x - thanks!
It would be nice to have a followup issue to port these tests to Drupal 8, I think.
I was wondering if there are any side effects from having a date format that is limited to the en-us locale as the first one on the list, but I couldn't find any problems. (It seems that locale info isn't really even used at all?)
I fixed the following on commit (since assertion messages shouldn't be translated):