Problem/Motivation

Up to Drupal 7, the default date format was the ISO standard YYYY-mm-dd Commands:HH:mm. So where the date format, couldn't be set (such in the node/add forms) this was used.
Users could also add a timezone correction, such as (+2). There is an issue for this regression #2632040: [PP-1] Add ability to select a timezone for datetime field.

In Drupal 8, a new "Fallback date format". This usese the US date format mm-dd-YY and a 12 hour clock with am/pm.
This date format is used in the US and a few other countries such as Marshall islands. The 12 hour clock with the am/pm suffix is only used in English and some Spanish speaking countries. Other languages don't have this concept for writing down times, and also no translation for "am/pm".

The date picker widget is hard-coded to use this fallback date format. This means that whenever uses the date picker, afterwards the form will display this US date format - no matter what other date formats the site uses. The user cannot change this.
Anybody who wants to type in the date is only sees mm/dd/yyyy.
This cannot be translated, even though it at least should be for example mm-tt-jjjj in German.

The time can be typed in the 24 hr format, but is then automatically changed to 12 hr format. Users have to choose AM or PM even if they have no idea what that means.

An example: If I enter date and time today using the date picker widget on a German Drupal site today, I expect something like 12-01-2018 16:00.
But what I see is 01/12/2018 04:00:00 pm. To me that looks like I mistyped, and I might correct it until I notice that it's getting changed every time. Or might look at this in a year or so, and wonder why I picked the wrong date....

I expect 12/01/2018 16:00 here.

If the user adds a date field to an entity this can at least be mitigated by choosing the select fields instead. That way we loose the ease of the date picker, but at least the date and time in the filled-in form doesn't look wrong.

However, the date picker widget is also hard-coded to be used for the "Authored on" field of the article and page content type. The user cannot change this, and it's not even possible to add any description text, to alert other users of the fact that this is in the US date format. This is even more confusing, when the short date format has been changed, because then the user sees two different date formats with no indication that this is the case. So it looks like two different dates.
To add insult to injury: the hard-coded description text still says that the date is in the format yyyy-mm-dd Commands:HH:mm.

So for the improved UX of having a date picker, we end up with one that only makes sense in the US, and a confusing UX experience for anybody outside the US who looks at the "Authored on" date on a node edit form.

Proposed resolution

The best solution would be if users could set the date format in which the picked date is displayed on the form.

This would ideally include both the order of day, month and year; their display; and the connectors (/ or - or so); as well as the display of the time. Obviously it needs ensuring that all 6 values are present.
Adding the timezone correction would fix the regression from D7 to D8 for the authored date for node content.

If this is not possible then there should at least should be two or three date options to choose from (yyyy-mm-dd, dd-mm-yyyy, mm/dd/yyyy) and the option to choose between 24 or 12 hr clock.

And the description text for the node edit form needs to be changed to reflect the changed date format.

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ifrik created an issue. See original summary.

mgifford’s picture

Issue tags: +localization

Interesting. So why is this an accessibility issue? What part of WCAG 2.0 or 2.1 does it interfere with.

Obviously it should be dealt with as part of a global CMS. I'm tagging for localization as that might attract more of the right folks.

mpdonadio’s picture

In Drupal 8, the date and time elements are HTML5 inputs, which will use your browser locale for display and the ISO formats internally regardless of what the site language is set for. Don't think we have any control of this.

I think everything in this issue is already covered in other issues (I know we have others about the format and descriptions). I will add them in when I go through the list.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

lomale@bluewin.ch’s picture

OK but I place it here again.

My question is what happens, that in the beginning it works and then suddenly stopped displaying correctly ??

since a while the date field is not displayed correctly any more. // see pictures

on local it's correct there is an calendar pop_up when i enter the field in the node_edit mode
picture : Date with POPupcalender

the date field look like that
picture : Datefields with Date and Time

the date field displayed not in the correct form under safari and firefox
picture : Date with no POPupcalender and wrong datestructure

in chrome it displays correctly with POPupcalender
picture : Date with in POPupcalender in chrome and correct date display

I run Drupal 8.4.4 in German. English and French
picture languages

who give me a hint how to fix that. where could i look for.
Thanks for the answer.

mgifford’s picture

Issue tags: -Accessibility

I think you're looking for something like this https://support.mozilla.org/en-US/questions/987697

mpdonadio’s picture

I suspect this may be a localization issue related to #1835016: Polyfill date input type, but I need to dig some more.

ok_lyndsey’s picture

FileSize
17.6 KB

This issue is also manifesting in the date picker in views. Assume related to core issue and fall back date format not being changed so adding to this issue.

I really feel like this was working previously and stopped after I updated to 8.4.3 - the labels and description text I added and tested, and I'm pretty sure it was fine. I think updated from 8.1 or 8.2.

date picker showing U.S. date format on input

mpdonadio’s picture

#8, what browser, and can you tell if that is a browser native picker or the polyfill one? Looking more like this is a problem with the polyfill w/ localization.

kreatIL’s picture

FileSize
98.5 KB

#9 I don't think the problem described here is due to the browser localization. I'm having the same issue with a date field. On Firefox and Chrome it displays as expected, on Safari desktop the date format is presented in the US english version. The preferred language settings are already set to German on the OS side in my case. I have no idea where to search for a solution. Any hint would be appreciated.
Screenshot Safari Chrome Firefox

mpdonadio’s picture

#10, thanks for the screenshots, they are a big help.

We may be seeing two intertwined and related issues here.

The screenshot in the issue summary shows what appears to be the Timestamp input widget on a HTML5 browser, and showing the US date and time formats.

Your screenshots are showing the Daterange widgets (which derive from the Datetime ones). The Firefox and Chrome shots show the HTML5 input, and your proper localization. The Safari one is using the jQuery polyfill for the date picker (desktop Safari does not have a native datepicker), and showing the date in ISO format (not what a US person would use), as that is the format for that widget.

I'll add the related issues when I can do through the queue to find them.

kreatIL’s picture

Thanks for the clarification, mpdonadio. I additionally tested it with a normal datetime field. I got the same behavior on the Safari browser. Maybe this is the related issue you mentioned? #2646454 Change the date format for the form display

andrezstar’s picture

#10 have the same issue for IExplorer.
Edit- You shall check this response. I think it does the trick https://www.drupal.org/project/drupal/issues/2646454#comment-12082042
The only thing is that the form validation wont accept this format for InternetExplorer.
It does validate for other browsers tho...
Weird, isnt it?

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mErilainen’s picture

I noticed that the date picker works fine on Firefox Quantum 61.0.2 (64-bit) on macOS but same version doesn't work on Win10. I have tried to set everything to Finnish in Drupal, OS and browser, but the date format is stuck on US format.

Then I installed the Firefox in Finnish to Win10 machine and the date picker switched to Finnish too. Seems that the native picker is using the browser UI language on Windows https://support.mozilla.org/en-US/questions/1018686

frederickjh’s picture

One tip when working on this and you are changing the language settings in FireFox and Google Chrome to set the HTML5 date format that the date will be displayed with, the changes to the HTML5 date format do not apply until you restart the browser. This is more obvious in FireFox as it adds a button that says to apply and restart.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

david.qdoscc’s picture

mpdonadio’s picture

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

jonathan1055’s picture

I have been trying to write a FunctionalJavascript tests which needs to fill in date field which has the browser HTML5 pop-up. The problem is that locally the tests need d/m/Y but on Drupal.org they need m/d/Y due to the different locale. Here's a hack that may help others to get round this in the test code:

    // Set the date using a day and month which could be correctly interpreted
    // either way. Set the year to be next year to ensure a future date.
    // Use a time format which includes 'pm' as this may be necessary, and will
    // be ignored if the time widget wants hh:mm:ss in 24 hours format.
    $page->fillField('edit-publish-on-0-value-date', '05/02/' . (date('Y') + 1));
    $page->fillField('edit-publish-on-0-value-time', '06:00:00pm');
    $page->pressButton('Save');
    $node = $this->drupalGetNodeByTitle($title);
    // If the saved month is 2 then the format is d/m/Y, otherwise it is m/d/Y.
    $this->datepickerFormat = (date('n', $node->publish_on->value) == 2 ? 'd/m/Y' : 'm/d/Y');

Sorry for posting a bit off-topic, but anyone likely to encounter the problem may well find this issue, just as I did.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

arx-e’s picture

This can be a really embarrassing issue as people just ask "but can't you fix it"?
I have installed British English as the default and it behaves better but this is not a solution.
It is very common in our part of the world for people to have their systems and their browsers interface language set in US English.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

colan’s picture

Does #2791693: Remove sample date from date field error message and title attribute fix the problem here, or does it just fix the messaging part?

vacho’s picture

@colan these patch for #2791693 only fix the message part, no the problem here.

vacho’s picture

This is needed to fix for the core.

However for now if someone is needed, can implement a hook update to get into the query the date in the format that is needed.

function module_name_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {
  if ($view->id() === 'some_name' && $view->current_display == 'some_page') {
    $input = $view->getExposedInput();
    foreach ($query->where as $i => $where) {
      foreach ($where as $j => $where_group) {
        if (is_array($where_group) && $j == 'conditions') {
          foreach ($where_group as $k => $condition) {
            if (strpos($condition['field'], 'node_field_data.published_at') !== FALSE) {
              $parts = explode(' ', $condition['field']);
              $separator = $parts[1];
              $date = NULL;
              switch ($separator) {
                case '>=':
                  $date = DateTime::createFromFormat(
                    'd/m/Y',
                    $input["published_at_start"],
                  );

                  break;

                case '<=':
                  $date = DateTime::createFromFormat(
                    'd/m/Y',
                    $input["published_at_end"],
                  );
                  break;
              }

              if ($date) {
                $condition['field'] = implode(' ', [
                  reset($parts),
                  $separator,
                  $date->getTimestamp(),
                ]);
                $query->where[$i]['conditions'][$k] = $condition;
              }
            }
          }
        }
      }
    }
  }
}

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

jaime@gingerrobot.com’s picture

Issue tags: +widget, +behaviors, +messaging, +field labels
elek’s picture

Thank you @mpdonadio, #3 made all clear for me. Don't know why I hat US-english instead of german in my browser settings. Well, I don't care or play around with those settings.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.