File /core/modules/locale/locale.datepicker.js, line 78:
dateFormat: Drupal.t('mm/dd/yy'),

This line sets a localized value for the setting dateFormat for jquery UI datepickers. However this setting should not be trnslated at all, as it should only use a give set of format characters (like the php date() function). See the jquery ui documentation: http://api.jqueryui.com/datepicker/#option-dateFormat

To solve just remove this line from this file in the locale module. If it should get a setting from Drupal at all, it should not be done in the locale module.

ScreenHunter_67 Apr. 22.jpg ScreenHunter_68 Apr. 22.jpg

These settings look erroneous to me as well:
- firstDay (line 79): is not a locale specific setting but a system wide setting, and thus should be set elsewhere (if it should be set at all).
- isRTL (line 80): should get a correct setting based on the current language.

Possibly related issues:
- #1761826: Add Date Format data to Drupal.settings.
- #507502: (needs documentation) Provide Locale support for jQuery UI (the issue that introduced or did not solve this and still needs documentation)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dboulet’s picture

Status: Active » Needs review
FileSize
460 bytes

Here’s a first patch to get things rolling.

Do we also need new tests to make sure that the datepickers are not broken again after this is fixed?

fietserwin’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Thanks for joiningthis issue.

I had another look at the code:
- locale_library_info_alter() adds values for firstDay and isRTL to drupal.settings.jquery.ui.datepicker. This property gets merged ("extended") with the values define here in js code. So they will be overwritten for sure and thus should be removed here too.
- dateFormat: Date format should probably get the short date format but without time parts. Or should it get the new HTML date format? But I'm not sure when and how that is supposed to be used. Another option is to introduce another new date format: date picker display format. Anyway, subsequently that PHP date format should be converted to a js (jquery ui datepicker) date format.

In a module I maintain, I already have code for that:

/**
 * Converts a PHP date format to a jQuery date picker format.
 *
 * @param string $format
 *   The date format to convert. If not given or empty, the (possibly localized)
 *   date format for the availability_calendar_date_display date type is
 *   converted.
 *
 * @return string
 */
function availability_calendar_get_date_format_for_js($format = '') {
  $format_conversions = array(
    'j' => 'd',
    'd' => 'dd',
    'z' => 'o',
    'D' => 'D',
    'l' => 'DD',
    'n' => 'm',
    'm' => 'mm',
    'M' => 'M',
    'F' => 'MM',
    'y' => 'y',
    'Y' => 'yy',
    'U' => '@',
    "'" => "''",
  );
  $needs_js_escape = array(
    'o',
    'd',
    'D',
    'm',
    'M',
    "y",
    '@',
    '!',
  );
  if (empty($format)) {
    $format = variable_get('date_format_availability_calendar_date_display', AC_DATE_DISPLAY);
  }
  $js_format = '';
  $is_escaped = FALSE;
  for ($i = 0; $i < strlen($format); $i++) {
    $char = $format[$i];
    if ($is_escaped || !array_key_exists($char, $format_conversions)) {
      if (!$is_escaped && $char === '\\') {
        // Next character is escaped. Skip this \.
        $is_escaped = TRUE;
      }
      else {
        // We are either escaping this character or it is not a format
        // character. In both cases we have to add this character as is, though
        // it may be a character that needs escaping in the js format.
        $js_format .= in_array($char, $needs_js_escape) ? "'$char'" : $char;
        $is_escaped = FALSE;
      }
    }
    else {
      // This is a non escaped to be converted character: replace the PHP format
      // with the js format.
      $js_format .= $format_conversions[$char];
    }
  }
  if ($is_escaped) {
    // A \ at the end of the PHP format, add it to the js format as well.
    $js_format .= '\\';
  }
  return $js_format;
}

With some minor changes, e.g. no look-up of a default date format, thus also no default value for the parameter, this code can be used as is. it would need some automated tests though.

fietserwin’s picture

Issue summary: View changes

Updated issue summary.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

amourow’s picture

Issue summary: View changes
FileSize
24.11 KB

We recently bumped to the issue in D7 that yy/mm/dd has been translated in zh_hant (月月/日日/年年) for a long time.
This causes datepicker get Uncaught Invalid Date when we use the popup date widget in views.

The format is still good to be "localize" for user to see the familiar date format. It should not be "translated", however the l.d.o server cannot provide sufficient context for translation contributor.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

alex_optim’s picture

Status: Needs work » Needs review
FileSize
468 bytes
chrotto’s picture

Getting the same result with #7 that in #1.
To get the right format (Swedish for me), I have to set the format in /core/modules/locale/locale.datepicker.js
Datepicker does not read the format from local settings.
Using core version 8.3.1

droplet’s picture

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

cslevy’s picture

Recreated patch for 8.4

chrotto’s picture

When is this included in module version?

droplet’s picture

Version: 8.4.x-dev » 8.5.x-dev
Issue tags: -Needs JavaScript testing +js-novice, +Quick fix
FileSize
1.47 KB

After some thoughts, I think we may not need a test here. We need a way to improve the docs to inherit it from jQuery UI docs.

anpolimus’s picture

Issue tags: +CSKyiv18
mohit1604’s picture

Status: Needs review » Reviewed & tested by the community

@droplet ! patch looks good . Marking RTBC .

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 13: 1976614-13.patch, failed testing. View results

mohit1604’s picture

Assigned: Unassigned » mohit1604
mohit1604’s picture

Status: Needs work » Needs review
FileSize
1.49 KB

This should work fine .

Status: Needs review » Needs work

The last submitted patch, 18: 1976614-18-D8.patch, failed testing. View results

droplet’s picture

Status: Needs work » Reviewed & tested by the community

random fails. we can skip

Wim Leers’s picture

Title: Setting dateFormat for datepicker should not be translated » Setting jQuery UI Datepicker's dateFormat should not be translated
Status: Reviewed & tested by the community » Needs work
Issue tags: +D8MI, +Needs tests
  1. #18 no longer contains docs that #13 contained.
  2. This does not yet have test coverage … ideally it would, but I agree that it's overkill here. it is very strange to see US-style date formatting in Europe (the screenshot in the IS is in Dutch). Shouldn't that be dd/mm/yy in Europe, and isn't that why this was being passed through Drupal.t() in the first place? Seems like this is tricky enough (not in code, but in consequences) that this merits test coverage.
mohit1604’s picture

Assigned: mohit1604 » Unassigned
fietserwin’s picture

RE#21.2: Yes, it should be localized, but IMO we should not use Drupal.t() for that, we have date formats for that.

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.

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.

Sutharsan’s picture

FileSize
1.48 KB

Re-rolling the #18 patch.

rafuel92’s picture

Hello guys, i've enqueued the tests for patch at #26

Shreya Shetty’s picture

Status: Needs work » Needs review

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.

kallado’s picture

I'm having the same problem with a portuguese site the datepicker returns 22/04/aa, it's fixed with the patch any reason why this change isn't already on the core?

mjchadwick’s picture

I'm at the DrupalCon 2019 Mentoring Contribution session and looking into this issue.

TARtech’s picture

I'm also at Drupalcon in Seattle at the mentored contributions and we are working on this.

mjchadwick’s picture

The patch applied cleanly for me. However, could someone post a set of steps to replicate the issue (starting with a base Drupal 8.8.x-dev install, and what modules/languages need to be installed/enabled)?

Thank you!

kallado’s picture

Guys its 2am in Portugal can't get on it now but if i can i'll get to it tomorrow.

joao.ramos.costa’s picture

FileSize
8.93 KB

Well, i reproduced it using the pt-pt language and the module Better Exposed Filters in a view exposed form .

- A content type with a Date field

- Create a view with a exposed filter for that field

- Exposed form style of that view :Better Exposed Filters ; In is settings Display "start" (field name) exposed filter as jqueryUI Datepicker.

When you access the view page with another language, i.e. pt-pt (in my case) , the value appears translated as the image shows above.

kallado’s picture

@joao.ramos ty i just didn't find time to do it. It seams like that should do it.

Quicksaver’s picture

I definitely agree with #23, the patch as it is will force US-style dates in datepickers. It should use one (any) of the existing date formats if possible instead to properly format the date.

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.

alternativo’s picture

Issue tags: -JavaScript +JavaScript

Hi, the patch#26 makes datepitcher working, but leave the english format date in the fields…
I test some solutions, but did not manage to solve...
Find this issue with this solution that for me is working

https://www.drupal.org/project/better_exposed_filters/issues/2858293 #5
1) go to /admin/config/regional/translate
2) search the string mm/dd/yy
3) translate to dd-mm-yy
4) save and flush caches
5) try to search a date

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.

eiriksm’s picture

Version: 9.1.x-dev » 8.9.x-dev
Status: Needs review » Needs work

This does not apply to Drupal 9, as jquery.ui.datepicker is removed from Drupal core.

Working on a quick test.

eiriksm’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
4.82 KB
6.11 KB

Alright here is a failing test (hopefully), and a patch with the fix and the same test.

The last submitted patch, 42: 1976614-test-only.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Status: Needs review » Needs work

The last submitted patch, 42: 1976614.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

eiriksm’s picture

Status: Needs work » Needs review
FileSize
5.06 KB
6.36 KB

Fixed up the coding standard, and hopefully the test will not fail because of timezones now

eiriksm’s picture

FileSize
5.43 KB
6.73 KB

OK, thought out an even better way to hopefully have the same timezone in the browser and the drupal site.

The last submitted patch, 45: 1976614.patch, failed testing. View results

The last submitted patch, 45: 1976614-test-only.patch, failed testing. View results

The last submitted patch, 46: 1976614-test-only.patch, failed testing. View results

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

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

JeroenT’s picture

Project: Drupal core » jQuery UI Datepicker
Version: 9.2.x-dev » 8.x-1.x-dev
Component: locale.module » Code
Status: Needs review » Needs work
Issue tags: +Bug Smash Initiative

Since jQuery UI Datepicker is no longer part of core, I'm moving this to the jQuery UI Datepicker module issue queue.

cslevy’s picture

I created a patch for jquery_ui_datepicker, but I didn't add any tests for it. Feel free to add test as well.

ivnish’s picture

Status: Needs work » Needs review
lo3001’s picture

I had the same problem on my website, it was working in German but not in French.
It's very odd but the following works for me on views filter (drupal 9) .

In user interface translation search the source string 'mm/dd/yy'
German translation was 'dd.mm.yy' (this one works)
French translation was 'dd/mm/yy' changing it to 'dd.mm.yy' made my views filter work.

Just saw someone already had a similar fix, for me replacing the slashes with dots or hyphen is a better solution.
Without the translation in most European country it would be confusing to have the date in another format.

sebasgd’s picture

Patch from #52 worked for me. A multisite in english and french and the date format was not correct in the exposed filter field for the french version of the page. In english the date format was mm/dd/yyyy and in french it was dd/mm/yyyy.