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.jpgScreenHunter_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)

Members fund testing for the Drupal project. Drupal Association Learn more

Comments

dboulet’s picture

Status: Active » Needs review
FileSize
460 bytes
PASSED: [[SimpleTest]]: [MySQL] 58,506 pass(es). View

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.