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
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tim.plunkett’s picture

Version: 7.16 » 8.x-dev
Priority: Major » Normal
Issue tags: +Needs backport to D7

Thanks for the bug report!
It will need to be fixed in D8 first.

marcingy’s picture

Status: Active » Postponed (maintainer needs more info)

dblog uses in d7

array('data' => t('Date'), 'header' => TRUE),
format_date($dblog->timestamp, 'long'),

Not the short date, so if you change the long date does what is displayed change?

wavesailor’s picture

My long date is specified as:

Tuesday, October 23, 2012 - 12:59

but /admin/reports/dblog displays the results as:

10/19/2012 - 16:07

wavesailor’s picture

Status: Postponed (maintainer needs more info) » Needs work
markpavlitski’s picture

Version: 8.x-dev » 7.x-dev
Component: dblog.module » system.module
Status: Needs work » Needs review
Issue tags: -Needs backport to D7
FileSize
1.32 KB
5.79 KB
15.07 KB

The 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():

        // Cells
        array('class' => 'icon'),
        t($dblog->type),
        format_date($dblog->timestamp, 'short'),
        ...

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 using hook_date_formats() and picks the first one if none are set. Both short and medium formats have a different first date (provided by system_date_formats() than the default value given to variable_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.

dawehner’s picture

I guess even for 7.x we have to adds tests.

markpavlitski’s picture

Status: Needs review » Needs work

The last submitted patch, 7: drupal-default-date-format-1817748-7.patch, failed testing.

markpavlitski’s picture

I've amended the patch to be more explicit when checking the date config page.

The last submitted patch, 9: drupal-default-date-format-1817748-9-test-only.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 9: drupal-default-date-format-1817748-9.patch, failed testing.

hgoto’s picture

The 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:

  function setUp() {
    parent::setUp(array('locale'));

    // Create admin user and log in admin user.
    $this->admin_user = $this->drupalCreateUser(array('administer site configuration'));
    $this->drupalLogin($this->admin_user);
  }

We should create a new test class with Locale module disabled to verify this patch, I think.

2.

+      // Check that the configuration fields match the default format.
+      $this->assertFieldByXPath(
+        "//select[@name=date_format_{$format_name}]/option[@selected='selected']",
+        $format_value,
+        t('The @type format type matches the expected format @format',
+        array(
+          '@type' => $format_name,
+          '@format' => $format_value,
+        )
+      ));

We may use DrupalWebTestCase::assertOptionSelected() here.

https://api.drupal.org/api/drupal/modules%21simpletest%21drupal_web_test...

markpavlitski’s picture

The last submitted patch, 13: drupal-default-date-format-1817748-13-test-only.patch, failed testing.

hgoto’s picture

Title: /admin/reports/dblog does not display the results using the correct date format specified for the site » /admin/config/regional/date-time does not show the correct default format for short and medium format
Issue summary: View changes

Now we are targeting the date and time setting page rather than the dblog page. Let's update the issue title and summary.

hgoto’s picture

Thank 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 :)

hgoto’s picture

Issue summary: View changes
Sophie.SK’s picture

Status: Needs review » Reviewed & tested by the community

Works 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.

markpavlitski’s picture

@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?

Sophie.SK’s picture

@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.

Fabianx’s picture

Issue tags: +Pending Drupal 7 commit

Marking for commit, nice work @all! :)

markpavlitski’s picture

Thanks @Fabianx! This issue has been bugging me for ages!

stefan.r’s picture

Assigned: Unassigned » David_Rothstein
Issue tags: +Drupal bugfix target

Looks good to me as well, assigning to David for final review

David_Rothstein’s picture

Assigned: David_Rothstein » Unassigned
Status: Reviewed & tested by the community » Fixed
Issue tags: -Pending Drupal 7 commit, -Drupal bugfix target +7.54 release notes

Committed 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):

diff --git a/modules/system/system.test b/modules/system/system.test
index 5571b7d..9eaf562 100644
--- a/modules/system/system.test
+++ b/modules/system/system.test
@@ -1505,7 +1505,7 @@ class DateFormatTestCase extends DrupalWebTestCase {
       $this->assertOptionSelected(
         $id,
         $format_value,
-        t('The @type format type matches the expected format @format',
+        format_string('The @type format type matches the expected format @format.',
         array(
           '@type' => $format_name,
           '@format' => $format_value,

  • David_Rothstein committed 8ad071f on 7.x
    Issue #1817748 by markpavlitski, hgoto, wavesailor, Sophie.SK: /admin/...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.