diff --git a/core/includes/common.inc b/core/includes/common.inc index 7625b90..19597d5 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -1921,18 +1921,16 @@ function format_date($timestamp, $type = 'system_medium', $format = '', $timezon $langcode = language(LANGUAGE_TYPE_INTERFACE)->langcode; } - // Handle the base case: $type == 'custom' - // if $type is custom use the format that is provided by the $format argument + // if we have a custom use the format use the user provided values. if ($type != 'custom') { - // Check for a localised version. - $format = config('locale.config.' . $langcode . '.system.date')->get('formats.' . $type . '.pattern.php'); + // Fall back too system_medium if a value was not found. + $format = config('system.date')->get('formats.' . $type . '.pattern'); + // Fall back too system_medium if a value was not found. if (!isset($format)) { - $format = config('system.date')->get('formats.' . $type . '.pattern.php'); - if (!isset($format)) { - // If that type didn't exist return format medium's value - $format = config('system.date')->get('formats.system_medium.pattern.php'); - } + $format = config('system.date')->get('formats.system_medium.pattern'); } + // Use the appropriate server pattern. + $format = system_get_date_format_pattern($format); } // Create a DateTime object from the timestamp. diff --git a/core/includes/form.inc b/core/includes/form.inc index eac1f2a..4105840 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -2963,7 +2963,8 @@ function form_process_date($element) { $element['#tree'] = TRUE; // Determine the order of day, month, year in the site's chosen date format. - $format = config('system.date')->get('formats.system_short.pattern.php'); + $format = config('system.date')->get('formats.system_short.pattern'); + $format = system_get_date_format_pattern($format); $sort = array(); $sort['day'] = max(strpos($format, 'd'), strpos($format, 'j')); $sort['month'] = max(strpos($format, 'm'), strpos($format, 'M')); diff --git a/core/modules/aggregator/aggregator.pages.inc b/core/modules/aggregator/aggregator.pages.inc index 6ff9520..aacdbd2 100644 --- a/core/modules/aggregator/aggregator.pages.inc +++ b/core/modules/aggregator/aggregator.pages.inc @@ -335,7 +335,8 @@ function template_preprocess_aggregator_item(&$variables) { $variables['source_date'] = t('%ago ago', array('%ago' => format_interval(REQUEST_TIME - $item->timestamp))); } else { - $variables['source_date'] = format_date($item->timestamp, 'custom', config('system.date')->get('formats.system_medium.pattern.php')); + $format = config('system.date')->get('formats.system_medium.pattern'); + $variables['source_date'] = format_date($item->timestamp, 'custom', system_get_date_format_pattern($format)); } $variables['categories'] = array(); diff --git a/core/modules/system/config/system.date.yml b/core/modules/system/config/system.date.yml index f0d39bc..f24cc0f 100644 --- a/core/modules/system/config/system.date.yml +++ b/core/modules/system/config/system.date.yml @@ -1,12 +1,12 @@ first_day: '0' country: - default: '' + default: '' timezone: - default: '' - user: - configurable: '1' - default: '0' - warn: '0' + default: '' + user: + configurable: '1' + default: '0' + warn: '0' formats: system_long: name: "Default Long Date" diff --git a/core/modules/system/lib/Drupal/system/Tests/System/DateFormatsLanguageTest.php b/core/modules/system/lib/Drupal/system/Tests/System/DateFormatsLanguageTest.php index 52f194e..71846f3 100644 --- a/core/modules/system/lib/Drupal/system/Tests/System/DateFormatsLanguageTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/System/DateFormatsLanguageTest.php @@ -19,7 +19,7 @@ class DateFormatsLanguageTest extends WebTestBase { * * @var array */ - public static $modules = array('node', 'language'); + public static $modules = array('node', 'locale'); public static function getInfo() { return array( diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index 1cd9107..50ae836 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -1959,7 +1959,7 @@ function system_regional_settings_submit($form, &$form_state) { * @see system_settings_form() */ function system_date_time_settings() { - // Display any user-defined date formats + // Display any user-defined date formats. $date_formats = system_get_date_formats(); $header = array( @@ -1971,7 +1971,7 @@ function system_date_time_settings() { $rows = array(); foreach ($date_formats as $dfid => $format_info) { - $pattern = system_get_date_format_pattern($format_info); + $pattern = system_get_date_format_pattern($format_info['pattern']); $rows[] = array( $dfid, $format_info['name'], @@ -2554,7 +2554,7 @@ function system_date_delete_format_form($form, &$form_state, $dfid) { '#value' => $dfid, ); $format = system_get_date_formats($dfid); - $pattern = system_get_date_format_pattern($format); + $pattern = system_get_date_format_pattern($format['pattern']); $output = confirm_form($form, t('Are you sure you want to remove the format %name : %format?', array('%name' => $format['name'], '%format' => format_date(REQUEST_TIME, 'custom', $pattern))), 'admin/config/regional/date-time/formats', @@ -2599,7 +2599,7 @@ function system_date_time_formats() { $row = array(); $row[] = array('data' => $dfid); $row[] = array('data' => $format_info['name']); - $row[] = array('data' => format_date(REQUEST_TIME, 'custom', system_get_date_format_pattern($format_info))); + $row[] = array('data' => format_date(REQUEST_TIME, 'custom', system_get_date_format_pattern($format_info['pattern']))); // Prepare Operational links $links = array(); @@ -2669,7 +2669,7 @@ function system_configure_date_formats_form($form, &$form_state, $dfid = '') { '#value' => $dfid, ); $format_info = system_get_date_formats($dfid); - $pattern = system_get_date_format_pattern($format_info); + $pattern = system_get_date_format_pattern($format_info['pattern']); $now = t('Displayed as %date', array('%date' => format_date(REQUEST_TIME, 'custom', $pattern))); } @@ -2832,7 +2832,7 @@ function system_date_format_localize_form($form, &$form_state, $langcode) { $choices = array(); foreach ($formats as $dfid => $format_info) { - $pattern = system_get_date_format_pattern($format_info); + $pattern = system_get_date_format_pattern($format_info['pattern']); // Ignore values that are localized. if (empty($format_info['locales'])) { $choices[$dfid] = format_date(REQUEST_TIME, 'custom', $pattern); @@ -2847,7 +2847,7 @@ function system_date_format_localize_form($form, &$form_state, $langcode) { if (!empty($locale_formats)) { $formats += $locale_formats; foreach ($locale_formats as $dfid => $format_info) { - $pattern = system_get_date_format_pattern($format_info); + $pattern = system_get_date_format_pattern($format_info['pattern']); $choices[$dfid] = format_date(REQUEST_TIME, 'custom', $pattern); } } @@ -2884,7 +2884,7 @@ function system_date_format_localize_form_submit($form, &$form_state) { foreach ($formats as $dfid => $format_info) { if (isset($form_state['values']['date_format_' . $dfid])) { $format = $form_state['values']['date_format_' . $dfid]; - $pattern = system_get_date_format_pattern($formats[$format]); + $pattern = system_get_date_format_pattern($formats[$format]['pattern']); system_date_format_localize_form_save($langcode, $dfid, $pattern); } } diff --git a/core/modules/system/system.module b/core/modules/system/system.module index cd32fa2..e26649e 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -2242,24 +2242,6 @@ function system_filetransfer_info() { * Implements hook_init(). */ function system_init() { - global $conf; - - $language_interface = language(LANGUAGE_TYPE_INTERFACE); - // For each date type (e.g. long, short), get the localized date format - // for the user's current language and override the default setting for it - // in $conf. This should happen on all pages except the date and time formats - // settings page, where we want to display the site default and not the - // localized version. - if (strpos(current_path(), 'admin/config/regional/date-time/formats') !== 0) { - $languages = array($language_interface->langcode); - - // Setup appropriate date formats for this locale. - $formats = system_get_localized_date_format($languages); - foreach ($formats as $format_type => $format) { - $conf[$format_type] = $format; - } - } - $path = drupal_get_path('module', 'system'); // Add the CSS for this module. These aren't in system.info, because they // need to be in the CSS_SYSTEM group rather than the CSS_DEFAULT group. @@ -2303,40 +2285,22 @@ function system_init() { * * @return * An array of date formats. - * - * @todo: http://drupal.org/node/1733316 may greatly reduce the complexity here - * it can provide php library level support for - * */ function system_get_localized_date_format($languages) { - $default_formats = system_get_date_formats(); - - // Temporary fix until localized formats are working. - return $default_formats; + $formats = array(); // Get list of different format types. foreach ($languages as $language) { - $date_formats = config('locale.config.' . $language->langcode . '.system.date')->get('formats'); + $date_formats = config('locale.config.' . $language . '.system.date')->get('formats'); if (!empty($date_formats)) { - // We have locale-specific date formats, so check for their types. If - // we're missing a type, use the default setting instead. - foreach ($format_types as $type => $type_info) { - // If format exists for this language, use it. - if (!empty($date_formats[$type])) { - $formats['date_format_' . $type] = $date_formats[$type]; - } - // Otherwise get default variable setting. If this is not set, default - // to the short format. - else { - $formats['date_format_' . $type] = variable_get('date_format_' . $type, $short_default); - } + foreach ($date_formats as $dfid => $data) { + // If a localized format exists for this language, use it. + $formats[$dfid] = $date_formats[$dfid]; } - - // Return on the first match. - return $formats; + break; } } - return $default_formats; + return $formats; } /** @@ -3666,33 +3630,30 @@ function system_get_date_formats($dfid = NULL) { return $date_formats; } - // @todo: throw exception if the date_format that has been requested doesn't exist - // Otherwise, return the specific date format return $date_formats[$dfid]; } /** - * Get the appropriate date format pattern for this server's php configuration + * Get the appropriate date format pattern for this server's php configuration. * * @param array $format_info * The date format information that is stored in configuration * * @return string * The date format pattern - * - * @todo: Add logic to return the pattern that is optimized for - * the IntlDateFormatter object / intl library */ function system_get_date_format_pattern($format_info) { - $pattern_type = system_get_date_format_pattern_type(); - return $format_info['pattern'][$pattern_type]; + return $format_info[system_get_date_format_pattern_type()]; } /** - * Get the appropriate date format pattern type so that pattern can be saved, retrieved properly + * Get the appropriate date format pattern type. + * + * For now this function defaults to php. * * @return string + * The format type. */ function system_get_date_format_pattern_type() { return 'php';