diff --git a/core/includes/common.inc b/core/includes/common.inc index 18641fc..89a6c77 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -1943,23 +1943,29 @@ function format_date($timestamp, $type = 'system_medium', $format = '', $timezon if (empty($langcode)) { $langcode = language(LANGUAGE_TYPE_INTERFACE)->langcode; } + $settings = array('langcode' => $langcode); + + // Create a DrupalDateTime object from the timestamp and timezone. + $date_time = new DrupalDateTime($timestamp, $timezones[$timezone]); + + // Find the appropriate format type. + $key = $date_time->canUseIntl() ? DrupalDateTime::INTL : DrupalDateTime::PHP; - // if we have an incoming custom date format use the provided date format pattern. + // if we have a non-custom date format use the provided date format pattern. if ($type != 'custom') { - $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.system_medium.pattern'); - } - // Use the appropriate server pattern. - $format = system_get_date_format_pattern($format); + $format = config('system.date')->get('formats.' . $type . '.pattern.' . $key); } - // Create a DrupalDateTime object from the timestamp and timezone. - $date_time = new DrupalDateTime($timestamp, $timezones[$timezone]); + // Fall back to system_medium if a value was not found. + if (empty($format)) { + $format = config('system.date')->get('formats.system_medium.pattern.' . $key); + } + + if ($key == DrupalDateTime::INTL) { + $settings['format_string_type'] = $key; + } // Call date_format(). - $settings = array('langcode' => $langcode); return $date_time->format($format, $settings); } diff --git a/core/includes/form.inc b/core/includes/form.inc index 9a73342..e724a47 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -2964,7 +2964,7 @@ function form_process_date($element) { // Determine the order of day, month, year in the site's chosen date format. $format = config('system.date')->get('formats.system_short.pattern'); - $format = system_get_date_format_pattern($format); + $format = $format['php']; $sort = array(); $sort['day'] = max(strpos($format, 'd'), strpos($format, 'j')); $sort['month'] = max(strpos($format, 'm'), strpos($format, 'M')); diff --git a/core/lib/Drupal/Core/Datetime/DrupalDateTime.php b/core/lib/Drupal/Core/Datetime/DrupalDateTime.php index 775e668..6d60656 100644 --- a/core/lib/Drupal/Core/Datetime/DrupalDateTime.php +++ b/core/lib/Drupal/Core/Datetime/DrupalDateTime.php @@ -60,7 +60,7 @@ public function __construct($time = 'now', $timezone = NULL, $format = NULL, $se // We can set the langcode and country using Drupal values. $settings['langcode'] = !empty($settings['langcode']) ? $settings['langcode'] : language(LANGUAGE_TYPE_INTERFACE)->langcode; - $settings['country'] = !empty($settings['country']) ? $settings['country'] : variable_get('site_default_country'); + $settings['country'] = !empty($settings['country']) ? $settings['country'] : config('system.date')->get('country.default'); // Instantiate the parent class. parent::__construct($time, $timezone, $format, $settings); diff --git a/core/modules/aggregator/aggregator.pages.inc b/core/modules/aggregator/aggregator.pages.inc index aacdbd2..c8d7a70 100644 --- a/core/modules/aggregator/aggregator.pages.inc +++ b/core/modules/aggregator/aggregator.pages.inc @@ -335,8 +335,7 @@ function template_preprocess_aggregator_item(&$variables) { $variables['source_date'] = t('%ago ago', array('%ago' => format_interval(REQUEST_TIME - $item->timestamp))); } else { - $format = config('system.date')->get('formats.system_medium.pattern'); - $variables['source_date'] = format_date($item->timestamp, 'custom', system_get_date_format_pattern($format)); + $variables['source_date'] = format_date($item->timestamp, 'system_medium'); } $variables['categories'] = array(); diff --git a/core/modules/system/config/system.date.yml b/core/modules/system/config/system.date.yml index 3565022..c2dfc78 100644 --- a/core/modules/system/config/system.date.yml +++ b/core/modules/system/config/system.date.yml @@ -12,49 +12,59 @@ formats: name: 'Default Long Date' pattern: php: 'l, F j, Y - H:i' + intl: 'EEEE, LLLL d, yyyy - kk:mm' locked: 0 system_medium: name: 'Default Medium Date' pattern: php: 'D, m/d/Y - H:i' + intl: 'ccc, MM/dd/yyyy - kk:mm' locked: 0 system_short: name: 'Default Short Date' pattern: php: 'm/d/Y - H:i' + intl: 'MM/dd/yyyy - kk:mm' locked: 0 html_datetime: name: 'HTML Datetime' pattern: php: 'Y-m-d\TH:i:sO' + intl: 'yyyy-MM-dd'Tkk:mm:ssZZ' locked: 1 html_date: name: 'HTML Date' pattern: php: 'Y-m-d' + intl: 'yyyy-MM-dd' locked: 1 html_time: name: 'HTML Time' pattern: php: 'H:i:s' + intl: 'H:mm:ss' locked: 1 html_yearless_date: name: 'HTML Yearless date' pattern: php: 'm-d' + intl: 'MM-d' locked: 1 html_week: name: 'HTML Week' pattern: php: 'Y-\WW' + intl: 'Y-'WW' locked: 1 html_month: name: 'HTML Month' pattern: php: 'Y-m' + intl: 'Y-MM' locked: 1 html_year: name: 'HTML Year' pattern: - php: 'Y' + php: 'Y' + intl: 'Y' locked: 1 diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index 84a5bd6..1f79f24 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -8,6 +8,7 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; +use Drupal\Core\Datetime\DrupalDateTime; /** * Menu callback; Provide the administration overview page. @@ -1976,12 +1977,11 @@ function system_date_time_settings() { $rows = array(); foreach ($date_formats as $date_format_id => $format_info) { - $pattern = system_get_date_format_pattern($format_info['pattern']); $rows[] = array( $date_format_id, $format_info['name'], $pattern, - format_date(REQUEST_TIME, 'custom', $pattern), + format_date(REQUEST_TIME, $date_format_id), ); } @@ -2551,9 +2551,8 @@ function system_date_delete_format_form($form, &$form_state, $date_format_id) { '#value' => $date_format_id, ); $format = system_get_date_formats($date_format_id); - $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))), + t('Are you sure you want to remove the format %name : %format?', array('%name' => $format['name'], '%format' => format_date(REQUEST_TIME, $date_format_id))), 'admin/config/regional/date-time/formats', t('This action cannot be undone.'), t('Remove'), t('Cancel'), @@ -2596,7 +2595,7 @@ function system_date_time_formats() { $row = array(); $row[] = array('data' => $date_format_id); $row[] = array('data' => $format_info['name']); - $row[] = array('data' => format_date(REQUEST_TIME, 'custom', system_get_date_format_pattern($format_info['pattern']))); + $row[] = array('data' => format_date(REQUEST_TIME, $date_format_id)); // Prepare Operational links $links = array(); @@ -2636,6 +2635,10 @@ function system_date_time_formats() { * modified. */ function system_configure_date_formats_form($form, &$form_state, $date_format_id = '') { + $formats = system_get_date_formats(); + $format_info = config('system.date')->get('formats.' . $date_format_id); + $patterns = $format_info['pattern']; + $pattern = class_exists('IntlDateFormatter') ? $patterns[DrupalDateTime::INTL] : $patterns[DrupalDateTime::PHP]; if (empty($date_format_id)) { $form['date_format_id'] = array( '#type' => 'machine_name', @@ -2653,9 +2656,7 @@ function system_configure_date_formats_form($form, &$form_state, $date_format_id '#type' => 'value', '#value' => $date_format_id, ); - $format_info = system_get_date_formats($date_format_id); - $pattern = system_get_date_format_pattern($format_info['pattern']); - $now = t('Displayed as %date', array('%date' => format_date(REQUEST_TIME, 'custom', $pattern))); + $now = t('Displayed as %date', array('%date' => format_date(REQUEST_TIME, $date_format_id))); } $form['date_format_name'] = array( @@ -2666,11 +2667,17 @@ function system_configure_date_formats_form($form, &$form_state, $date_format_id '#default_value' => empty($format_info['name']) ? '' : $format_info['name'] ); + if (class_exists('intlDateFormatter')) { + $description = t('A user-defined date format. See the PHP manual for available options.', array('@url' => 'http://userguide.icu-project.org/formatparse/datetime')); + } + else { + $description = t('A user-defined date format. See the PHP manual for available options.', array('@url' => 'http://php.net/manual/function.date.php')); + } $form['date_format_pattern'] = array( '#type' => 'textfield', '#title' => t('Format string'), '#maxlength' => 100, - '#description' => t('A user-defined date format. See the PHP manual for available options.', array('@url' => 'http://php.net/manual/function.date.php')), + '#description' => $description, '#default_value' => empty($pattern) ? '' : $pattern, '#field_suffix' => ' ' . $now . '', '#ajax' => array( @@ -2738,7 +2745,7 @@ function system_add_date_formats_form_validate($form, &$form_state) { * Process new date format string submission. */ function system_add_date_formats_form_submit($form, &$form_state) { - $pattern_type = system_get_date_format_pattern_type(); + $pattern_type = class_exists('intlDateFormatter') ? DrupalDateTime::INTL : DrupalDateTime::PHP; $format = array(); $format['name'] = check_plain($form_state['values']['date_format_name']); $format['pattern'][$pattern_type] = trim($form_state['values']['date_format_pattern']); @@ -2817,10 +2824,9 @@ function system_date_format_localize_form($form, &$form_state, $langcode) { $formats = system_get_date_formats(); $choices = array(); foreach ($formats as $date_format_id => $format_info) { - $pattern = system_get_date_format_pattern($format_info['pattern']); // Ignore values that are localized. if (empty($format_info['locales'])) { - $choices[$date_format_id] = format_date(REQUEST_TIME, 'custom', $pattern); + $choices[$date_format_id] = format_date(REQUEST_TIME, $date_format_id); } else { unset($formats[$date_format_id]); @@ -2832,8 +2838,7 @@ function system_date_format_localize_form($form, &$form_state, $langcode) { if (!empty($locale_formats)) { $formats += $locale_formats; foreach ($locale_formats as $date_format_id => $format_info) { - $pattern = system_get_date_format_pattern($format_info['pattern']); - $choices[$date_format_id] = format_date(REQUEST_TIME, 'custom', $pattern); + $choices[$date_format_id] = format_date(REQUEST_TIME, $date_format_id); } } diff --git a/core/modules/system/system.module b/core/modules/system/system.module index d774911..6ff72fc 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -2385,7 +2385,7 @@ function system_user_presave($account) { /** * Implements hook_user_login(). */ -function system_user_login(&$edit, $account) { +function system_user_login($edit, $account) { $config = config('system.date'); // If the user has a NULL time zone, notify them to set a time zone. if (!$account->timezone && $config->get('timezone.user.configurable') && $config->get('timezone.user.warn')) { @@ -3643,33 +3643,6 @@ function system_get_date_formats($date_format_id = NULL) { } /** - * Gets the appropriate date format pattern for this server's php configuration. - * - * @param array $pattern - * The date pattern information that is stored in configuration - * - * @return string - * The date format pattern - */ -function system_get_date_format_pattern($pattern) { - return $pattern[system_get_date_format_pattern_type()]; -} - -/** - * Gets the appropriate date format pattern type. - * - * For now this function defaults to php. - * - * @return string - * The format type. - * - * @todo: Decide if this function is needed or if Date Component can handle this. - */ -function system_get_date_format_pattern_type() { - return 'php'; -} - -/** * Gets the appropriate date format string for a date type and locale. * * @param $langcode