diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 7c2f6bf..65a0506 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2172,13 +2172,16 @@ function drupal_bootstrap($phase = NULL, $new_phase = TRUE) { */ function drupal_get_user_timezone() { global $user; - if (variable_get('configurable_timezones', 1) && $user->uid && $user->timezone) { + $config = config('system.date'); + + if ($config->get('timezone.user.configurable') && $user->uid && $user->timezone) { return $user->timezone; } else { // Ignore PHP strict notice if time zone has not yet been set in the php.ini // configuration. - return variable_get('date_default_timezone', @date_default_timezone_get()); + $config_data_default_timezone = $config->get('timezone.default'); + return !empty($config_data_default_timezone) ? $config_data_default_timezone : @date_default_timezone_get(); } } diff --git a/core/includes/common.inc b/core/includes/common.inc index f1a7ce0..cddd837 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -1900,14 +1900,14 @@ function format_interval($interval, $granularity = 2, $langcode = NULL) { * A UNIX timestamp to format. * @param $type * (optional) The format to use, one of: - * - One of the built-in formats: 'short', 'medium', 'long', 'html_datetime', - * 'html_date', 'html_time', 'html_yearless_date', 'html_week', - * 'html_month', 'html_year'. - * - The name of a date type defined by a module in hook_date_format_types(), - * if it's been assigned a format. + * - One of the built-in formats: 'system_short', 'system_medium', + * 'system_long', 'html_datetime', 'html_date', 'html_time', + * 'html_yearless_date', 'html_week', 'html_month', 'html_year'. + * - The name of a date type defined by a module in + * hook_date_format_types(), if it's been assigned a format. * - The machine name of an administrator-defined date format. * - 'custom', to use $format. - * Defaults to 'medium'. + * Defaults to 'system_medium'. * @param $format * (optional) If $type is 'custom', a PHP date format string suitable for * input to date(). Use a backslash to escape ordinary text, so it does not @@ -1923,7 +1923,7 @@ function format_interval($interval, $granularity = 2, $langcode = NULL) { * @return * A translated date string in the requested format. */ -function format_date($timestamp, $type = 'medium', $format = '', $timezone = NULL, $langcode = NULL) { +function format_date($timestamp, $type = 'system_medium', $format = '', $timezone = NULL, $langcode = NULL) { // Use the advanced drupal_static() pattern, since this is called very often. static $drupal_static_fast; if (!isset($drupal_static_fast)) { @@ -1944,66 +1944,28 @@ function format_date($timestamp, $type = 'medium', $format = '', $timezone = NUL $langcode = language(LANGUAGE_TYPE_INTERFACE)->langcode; } - switch ($type) { - case 'short': - $format = variable_get('date_format_short', 'm/d/Y - H:i'); - break; - - case 'long': - $format = variable_get('date_format_long', 'l, F j, Y - H:i'); - break; - - case 'html_datetime': - $format = variable_get('date_format_html_datetime', 'Y-m-d\TH:i:sO'); - break; - - case 'html_date': - $format = variable_get('date_format_html_date', 'Y-m-d'); - break; - - case 'html_time': - $format = variable_get('date_format_html_time', 'H:i:s'); - break; - - case 'html_yearless_date': - $format = variable_get('date_format_html_yearless_date', 'm-d'); - break; - - case 'html_week': - $format = variable_get('date_format_html_week', 'Y-\WW'); - break; - - case 'html_month': - $format = variable_get('date_format_html_month', 'Y-m'); - break; - - case 'html_year': - $format = variable_get('date_format_html_year', 'Y'); - break; + // Create a DrupalDateTime object from the timestamp and timezone. + $date = new DrupalDateTime($timestamp, $timezones[$timezone]); - case 'custom': - // No change to format. - break; + // Find the appropriate format type. + $key = $date->canUseIntl() ? DrupalDateTime::INTL : DrupalDateTime::PHP; - case 'medium': - default: - // Retrieve the format of the custom $type passed. - if ($type != 'medium') { - $format = variable_get('date_format_' . $type, ''); - } - // Fall back to 'medium'. - if ($format === '') { - $format = variable_get('date_format_medium', 'D, m/d/Y - H:i'); - } - break; + // 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.' . $key); } - // Create a DrupalDateTime object from the timestamp and timezone. - $date_time = new DrupalDateTime($timestamp, $timezones[$timezone]); + // Fall back to system_medium if a format was not found. + if (empty($format)) { + $format = config('system.date')->get('formats.system_medium.pattern.' . $key); + } - // Call date_format(). - $settings = array('langcode' => $langcode); - return $date_time->format($format, $settings); + // Call $date->format(). + $settings = array( + 'langcode' => $langcode, + 'format_string_type' => $key, + ); + return $date->format($format, $settings); } /** diff --git a/core/includes/date.inc b/core/includes/date.inc deleted file mode 100644 index 01ab131..0000000 --- a/core/includes/date.inc +++ /dev/null @@ -1,196 +0,0 @@ - 'short', - 'format' => 'Y-m-d H:i', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'short', - 'format' => 'm/d/Y - H:i', - 'locales' => array('en-us'), - ); - $formats[] = array( - 'type' => 'short', - 'format' => 'd/m/Y - H:i', - 'locales' => array('en-gb', 'en-hk', 'en-ie', 'el-gr', 'es-es', 'fr-be', 'fr-fr', 'fr-lu', 'it-it', 'nl-be', 'pt-pt'), - ); - $formats[] = array( - 'type' => 'short', - 'format' => 'Y/m/d - H:i', - 'locales' => array('en-ca', 'fr-ca', 'no-no', 'sv-se'), - ); - $formats[] = array( - 'type' => 'short', - 'format' => 'd.m.Y - H:i', - 'locales' => array('de-ch', 'de-de', 'de-lu', 'fi-fi', 'fr-ch', 'is-is', 'pl-pl', 'ro-ro', 'ru-ru'), - ); - $formats[] = array( - 'type' => 'short', - 'format' => 'm/d/Y - g:ia', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'short', - 'format' => 'd/m/Y - g:ia', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'short', - 'format' => 'Y/m/d - g:ia', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'short', - 'format' => 'M j Y - H:i', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'short', - 'format' => 'j M Y - H:i', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'short', - 'format' => 'Y M j - H:i', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'short', - 'format' => 'M j Y - g:ia', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'short', - 'format' => 'j M Y - g:ia', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'short', - 'format' => 'Y M j - g:ia', - 'locales' => array(), - ); - - // Medium date formats. - $formats[] = array( - 'type' => 'medium', - 'format' => 'D, Y-m-d H:i', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'medium', - 'format' => 'D, m/d/Y - H:i', - 'locales' => array('en-us'), - ); - $formats[] = array( - 'type' => 'medium', - 'format' => 'D, d/m/Y - H:i', - 'locales' => array('en-gb', 'en-hk', 'en-ie', 'el-gr', 'es-es', 'fr-be', 'fr-fr', 'fr-lu', 'it-it', 'nl-be', 'pt-pt'), - ); - $formats[] = array( - 'type' => 'medium', - 'format' => 'D, Y/m/d - H:i', - 'locales' => array('en-ca', 'fr-ca', 'no-no', 'sv-se'), - ); - $formats[] = array( - 'type' => 'medium', - 'format' => 'F j, Y - H:i', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'medium', - 'format' => 'j F, Y - H:i', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'medium', - 'format' => 'Y, F j - H:i', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'medium', - 'format' => 'D, m/d/Y - g:ia', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'medium', - 'format' => 'D, d/m/Y - g:ia', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'medium', - 'format' => 'D, Y/m/d - g:ia', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'medium', - 'format' => 'F j, Y - g:ia', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'medium', - 'format' => 'j F Y - g:ia', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'medium', - 'format' => 'Y, F j - g:ia', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'medium', - 'format' => 'j. F Y - G:i', - 'locales' => array(), - ); - - // Long date formats. - $formats[] = array( - 'type' => 'long', - 'format' => 'l, F j, Y - H:i', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'long', - 'format' => 'l, j F, Y - H:i', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'long', - 'format' => 'l, Y, F j - H:i', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'long', - 'format' => 'l, F j, Y - g:ia', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'long', - 'format' => 'l, j F Y - g:ia', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'long', - 'format' => 'l, Y, F j - g:ia', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'long', - 'format' => 'l, j. F Y - G:i', - 'locales' => array(), - ); - - return $formats; -} diff --git a/core/includes/form.inc b/core/includes/form.inc index 226d4a6..c874e7f 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 = variable_get('date_format_short', 'm/d/Y - H:i'); + $format = config('system.date')->get('formats.system_short.pattern'); + $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/includes/install.core.inc b/core/includes/install.core.inc index 1790594..3142a9c 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -1936,7 +1936,7 @@ function _install_configure_form($form, &$form_state, &$install_state) { '#type' => 'select', '#title' => st('Default country'), '#empty_value' => '', - '#default_value' => variable_get('site_default_country', NULL), + '#default_value' => config('system.date')->get('country.default'), '#options' => $countries, '#description' => st('Select the default country for the site.'), '#weight' => 0, @@ -2009,8 +2009,10 @@ function install_configure_form_submit($form, &$form_state) { ->set('mail', $form_state['values']['site_mail']) ->save(); - variable_set('date_default_timezone', $form_state['values']['date_default_timezone']); - variable_set('site_default_country', $form_state['values']['site_default_country']); + config('system.date') + ->set('timezone.default', $form_state['values']['date_default_timezone']) + ->set('country.default', $form_state['values']['site_default_country']) + ->save(); // Enable update.module if this option was selected. if ($form_state['values']['update_status_module'][1]) { 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 78ca5bc..c8d7a70 100644 --- a/core/modules/aggregator/aggregator.pages.inc +++ b/core/modules/aggregator/aggregator.pages.inc @@ -335,7 +335,7 @@ 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', variable_get('date_format_medium', 'D, m/d/Y - H:i')); + $variables['source_date'] = format_date($item->timestamp, 'system_medium'); } $variables['categories'] = array(); diff --git a/core/modules/comment/comment.admin.inc b/core/modules/comment/comment.admin.inc index 26e9c8b..2736e7d 100644 --- a/core/modules/comment/comment.admin.inc +++ b/core/modules/comment/comment.admin.inc @@ -128,7 +128,7 @@ function comment_admin_overview($form, &$form_state, $arg) { '#href' => 'node/' . $comment->nid, ), ), - 'changed' => format_date($comment->changed, 'short'), + 'changed' => format_date($comment->changed, 'system_short'), ); $links = array(); $links['edit'] = array( diff --git a/core/modules/comment/comment.tokens.inc b/core/modules/comment/comment.tokens.inc index c77cb67..b15d79e 100644 --- a/core/modules/comment/comment.tokens.inc +++ b/core/modules/comment/comment.tokens.inc @@ -186,11 +186,11 @@ function comment_tokens($type, $tokens, array $data = array(), array $options = break; case 'created': - $replacements[$original] = format_date($comment->created, 'medium', '', NULL, $langcode); + $replacements[$original] = format_date($comment->created, 'system_medium', '', NULL, $langcode); break; case 'changed': - $replacements[$original] = format_date($comment->changed, 'medium', '', NULL, $langcode); + $replacements[$original] = format_date($comment->changed, 'system_medium', '', NULL, $langcode); break; case 'node': diff --git a/core/modules/dblog/dblog.admin.inc b/core/modules/dblog/dblog.admin.inc index 3b56f45..2f45565 100644 --- a/core/modules/dblog/dblog.admin.inc +++ b/core/modules/dblog/dblog.admin.inc @@ -63,7 +63,7 @@ function dblog_overview() { // Cells array('class' => 'icon'), t($dblog->type), - format_date($dblog->timestamp, 'short'), + format_date($dblog->timestamp, 'system_short'), theme('dblog_message', array('event' => $dblog, 'link' => TRUE)), theme('username', array('account' => $dblog)), filter_xss($dblog->link), @@ -162,7 +162,7 @@ function dblog_event($id) { ), array( array('data' => t('Date'), 'header' => TRUE), - format_date($dblog->timestamp, 'long'), + format_date($dblog->timestamp, 'system_long'), ), array( array('data' => t('User'), 'header' => TRUE), diff --git a/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php b/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php index 4d56b7b..187c41e 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php @@ -56,8 +56,8 @@ function testFileTokenReplacement() { $tests['[file:mime]'] = check_plain($file->filemime); $tests['[file:size]'] = format_size($file->filesize); $tests['[file:url]'] = check_plain(file_create_url($file->uri)); - $tests['[file:timestamp]'] = format_date($file->timestamp, 'medium', '', NULL, $language_interface->langcode); - $tests['[file:timestamp:short]'] = format_date($file->timestamp, 'short', '', NULL, $language_interface->langcode); + $tests['[file:timestamp]'] = format_date($file->timestamp, 'system_medium', '', NULL, $language_interface->langcode); + $tests['[file:timestamp:short]'] = format_date($file->timestamp, 'system_short', '', NULL, $language_interface->langcode); $tests['[file:owner]'] = check_plain(user_format_name($this->admin_user)); $tests['[file:owner:uid]'] = $file->uid; diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 85ed5d1..7ed44b6 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -573,7 +573,7 @@ function locale_library_info_alter(&$libraries, $module) { 'ui' => array( 'datepicker' => array( 'isRTL' => $language_interface->direction == LANGUAGE_RTL, - 'firstDay' => variable_get('date_first_day', 0), + 'firstDay' => config('system.date')->get('first_day'), ), ), ), diff --git a/core/modules/node/node.admin.inc b/core/modules/node/node.admin.inc index bca4dc2..4cdc606 100644 --- a/core/modules/node/node.admin.inc +++ b/core/modules/node/node.admin.inc @@ -539,7 +539,7 @@ function node_admin_nodes() { 'type' => check_plain(node_get_type_label($node)), 'author' => theme('username', array('account' => $node)), 'status' => $node->status ? t('published') : t('not published'), - 'changed' => format_date($node->changed, 'short'), + 'changed' => format_date($node->changed, 'system_short'), ); if ($multilingual) { $options[$node->nid]['language_name'] = language_name($node->langcode); diff --git a/core/modules/node/node.pages.inc b/core/modules/node/node.pages.inc index a71f5eb..f5b497a 100644 --- a/core/modules/node/node.pages.inc +++ b/core/modules/node/node.pages.inc @@ -268,13 +268,13 @@ function node_revision_overview($node) { foreach ($revisions as $revision) { $row = array(); if ($revision->current_vid > 0) { - $row[] = array('data' => t('!date by !username', array('!date' => l(format_date($revision->timestamp, 'short'), "node/$node->nid"), '!username' => theme('username', array('account' => $revision)))) + $row[] = array('data' => t('!date by !username', array('!date' => l(format_date($revision->timestamp, 'system_short'), "node/$node->nid"), '!username' => theme('username', array('account' => $revision)))) . (($revision->log != '') ? '

' . filter_xss($revision->log) . '

' : ''), 'class' => array('revision-current')); $row[] = array('data' => drupal_placeholder(t('current revision')), 'class' => array('revision-current')); } else { - $row[] = t('!date by !username', array('!date' => l(format_date($revision->timestamp, 'short'), "node/$node->nid/revisions/$revision->vid/view"), '!username' => theme('username', array('account' => $revision)))) + $row[] = t('!date by !username', array('!date' => l(format_date($revision->timestamp, 'system_short'), "node/$node->nid/revisions/$revision->vid/view"), '!username' => theme('username', array('account' => $revision)))) . (($revision->log != '') ? '

' . filter_xss($revision->log) . '

' : ''); if ($revert_permission) { $links['revert'] = array( diff --git a/core/modules/node/node.tokens.inc b/core/modules/node/node.tokens.inc index 0bd1000..09aa1c6 100644 --- a/core/modules/node/node.tokens.inc +++ b/core/modules/node/node.tokens.inc @@ -163,11 +163,11 @@ function node_tokens($type, $tokens, array $data = array(), array $options = arr break; case 'created': - $replacements[$original] = format_date($node->created, 'medium', '', NULL, $langcode); + $replacements[$original] = format_date($node->created, 'system_medium', '', NULL, $langcode); break; case 'changed': - $replacements[$original] = format_date($node->changed, 'medium', '', NULL, $langcode); + $replacements[$original] = format_date($node->changed, 'system_medium', '', NULL, $langcode); break; } } diff --git a/core/modules/openid/lib/Drupal/openid/Tests/OpenIDRegistrationTest.php b/core/modules/openid/lib/Drupal/openid/Tests/OpenIDRegistrationTest.php index debb9cd..9822ff9 100644 --- a/core/modules/openid/lib/Drupal/openid/Tests/OpenIDRegistrationTest.php +++ b/core/modules/openid/lib/Drupal/openid/Tests/OpenIDRegistrationTest.php @@ -41,8 +41,11 @@ function setUp() { */ function testRegisterUserWithEmailVerification() { config('user.settings')->set('verify_mail', TRUE)->save(); - variable_get('configurable_timezones', 1); - variable_set('date_default_timezone', 'Europe/Brussels'); + + config('system.date') + ->set('timezone.user.configurable', 1) + ->set('timezone.default', 'Europe/Brussels') + ->save(); // Tell openid_test.module to respond with these SREG fields. variable_set('openid_test_response', array( @@ -98,8 +101,11 @@ function testRegisterUserWithEmailVerification() { */ function testRegisterUserWithoutEmailVerification() { config('user.settings')->set('verify_mail', FALSE)->save(); - variable_get('configurable_timezones', 1); - variable_set('date_default_timezone', 'Europe/Brussels'); + + config('system.date') + ->set('timezone.user.configurable', 1) + ->set('timezone.default', 'Europe/Brussels') + ->save(); // Tell openid_test.module to respond with these SREG fields. variable_set('openid_test_response', array( @@ -139,8 +145,10 @@ function testRegisterUserWithoutEmailVerification() { * information (a username that is already taken, and no e-mail address). */ function testRegisterUserWithInvalidSreg() { - variable_get('configurable_timezones', 1); - variable_set('date_default_timezone', 'Europe/Brussels'); + config('system.date') + ->set('timezone.user.configurable', 1) + ->set('timezone.default', 'Europe/Brussels') + ->save(); // Tell openid_test.module to respond with these SREG fields. $web_user = $this->drupalCreateUser(array()); @@ -190,7 +198,6 @@ function testRegisterUserWithInvalidSreg() { * information (i.e. no username or e-mail address). */ function testRegisterUserWithoutSreg() { - variable_get('configurable_timezones', 1); // Load the front page to get the user login block. $this->drupalGet(''); @@ -230,7 +237,9 @@ function testRegisterUserWithoutSreg() { */ function testRegisterUserWithAXButNoSREG() { config('user.settings')->set('verify_mail', FALSE)->save(); - variable_set('date_default_timezone', 'Europe/Brussels'); + config('system.date') + ->set('timezone.default', 'Europe/Brussels') + ->save(); // Tell openid_test.module to respond with these AX fields. variable_set('openid_test_response', array( diff --git a/core/modules/search/search.pages.inc b/core/modules/search/search.pages.inc index b6a1930..9d99063 100644 --- a/core/modules/search/search.pages.inc +++ b/core/modules/search/search.pages.inc @@ -122,7 +122,7 @@ function template_preprocess_search_result(&$variables) { $info['user'] = $result['user']; } if (!empty($result['date'])) { - $info['date'] = format_date($result['date'], 'short'); + $info['date'] = format_date($result['date'], 'system_short'); } if (isset($result['extra']) && is_array($result['extra'])) { $info = array_merge($info, $result['extra']); diff --git a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsTokenReplaceTest.php b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsTokenReplaceTest.php index 0b5909d..dd25d52 100644 --- a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsTokenReplaceTest.php +++ b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsTokenReplaceTest.php @@ -46,7 +46,7 @@ function testStatisticsTokenReplacement() { $tests['[node:total-count]'] = 1; $tests['[node:day-count]'] = 1; $tests['[node:last-view]'] = format_date($statistics['timestamp']); - $tests['[node:last-view:short]'] = format_date($statistics['timestamp'], 'short'); + $tests['[node:last-view:short]'] = format_date($statistics['timestamp'], 'system_short'); // Test to make sure that we generated something for each token. $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.'); diff --git a/core/modules/system/config/system.date.yml b/core/modules/system/config/system.date.yml new file mode 100644 index 0000000..a1b1120 --- /dev/null +++ b/core/modules/system/config/system.date.yml @@ -0,0 +1,70 @@ +first_day: '0' +country: + default: '' +timezone: + default: '' + user: + configurable: '1' + default: '0' + warn: '0' +formats: + system_long: + 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' + intl: 'Y' + locked: 1 diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php index d3cd9e6..5b73eac 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php @@ -35,15 +35,19 @@ public static function getInfo() { } function setUp() { - parent::setUp(); - variable_set('configurable_timezones', 1); - variable_set('date_format_long', 'l, j. F Y - G:i'); - variable_set('date_format_medium', 'j. F Y - G:i'); - variable_set('date_format_short', 'Y M j - g:ia'); + parent::setUp('language'); + config('system.date') + ->set('timezone.user.configurable', 1) + ->set('formats.system_long.pattern.php', 'l, j. F Y - G:i') + ->set('formats.system_medium.pattern.php', 'j. F Y - G:i') + ->set('formats.system_short.pattern.php', 'Y M j - g:ia') + ->save(); + variable_set('locale_custom_strings_' . self::LANGCODE, array( '' => array('Sunday' => 'domingo'), 'Long month name' => array('March' => 'marzo'), )); + $this->refreshVariables(); } @@ -57,20 +61,16 @@ function testAdminDefinedFormatDate() { // Add new date format. $admin_date_format = 'j M y'; - $edit = array('date_format' => $admin_date_format); - $this->drupalPost('admin/config/regional/date-time/formats/add', $edit, 'Add format'); - - // Add new date type. $edit = array( - 'date_type' => 'Example Style', - 'machine_name' => 'example_style', - 'date_format' => $admin_date_format, + 'date_format_id' => 'example_style', + 'date_format_name' => 'Example Style', + 'date_format_pattern' => $admin_date_format, ); - $this->drupalPost('admin/config/regional/date-time/types/add', $edit, 'Add date type'); + $this->drupalPost('admin/config/regional/date-time/formats/add', $edit, t('Add format')); $timestamp = strtotime('2007-03-10T00:00:00+00:00'); $this->assertIdentical(format_date($timestamp, 'example_style', '', 'America/Los_Angeles'), '9 Mar 07', 'Test format_date() using an admin-defined date type.'); - $this->assertIdentical(format_date($timestamp, 'undefined_style'), format_date($timestamp, 'medium'), 'Test format_date() defaulting to medium when $type not found.'); + $this->assertIdentical(format_date($timestamp, 'undefined_style'), format_date($timestamp, 'system_medium'), 'Test format_date() defaulting to medium when $type not found.'); } /** @@ -123,9 +123,9 @@ function testFormatDate() { $this->assertIdentical(format_date($timestamp, 'custom', 'l, d-M-y H:i:s T', 'America/Los_Angeles', 'en'), 'Sunday, 25-Mar-07 17:00:00 PDT', 'Test a different language.'); $this->assertIdentical(format_date($timestamp, 'custom', 'l, d-M-y H:i:s T', 'Europe/London'), 'Monday, 26-Mar-07 01:00:00 BST', 'Test a different time zone.'); $this->assertIdentical(format_date($timestamp, 'custom', 'l, d-M-y H:i:s T'), 'domingo, 25-Mar-07 17:00:00 PDT', 'Test custom date format.'); - $this->assertIdentical(format_date($timestamp, 'long'), 'domingo, 25. marzo 2007 - 17:00', 'Test long date format.'); - $this->assertIdentical(format_date($timestamp, 'medium'), '25. marzo 2007 - 17:00', 'Test medium date format.'); - $this->assertIdentical(format_date($timestamp, 'short'), '2007 Mar 25 - 5:00pm', 'Test short date format.'); + $this->assertIdentical(format_date($timestamp, 'system_long'), 'domingo, 25. marzo 2007 - 17:00', 'Test long date format.'); + $this->assertIdentical(format_date($timestamp, 'system_medium'), '25. marzo 2007 - 17:00', 'Test medium date format.'); + $this->assertIdentical(format_date($timestamp, 'system_short'), '2007 Mar 25 - 5:00pm', 'Test short date format.'); $this->assertIdentical(format_date($timestamp), '25. marzo 2007 - 17:00', 'Test default date format.'); // Test HTML time element formats. $this->assertIdentical(format_date($timestamp, 'html_datetime'), '2007-03-25T17:00:00-0700', 'Test html_datetime date format.'); diff --git a/core/modules/system/lib/Drupal/system/Tests/Datetime/DrupalDateTimeTest.php b/core/modules/system/lib/Drupal/system/Tests/Datetime/DrupalDateTimeTest.php index ea10896..5539a61 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Datetime/DrupalDateTimeTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Datetime/DrupalDateTimeTest.php @@ -48,8 +48,8 @@ public function testDateTimezone() { $date_string = '2007-01-31 21:00:00'; // Make sure no site timezone has been set. - variable_set('date_default_timezone', NULL); - variable_set('configurable_timezones', 0); + config('system.date')->set('timezone.default', NULL)->save(); + config('system.date')->set('timezone.user.configurable', 0)->save(); // Detect the system timezone. $system_timezone = date_default_timezone_get(); @@ -66,7 +66,7 @@ public function testDateTimezone() { $this->assertTrue($timezone == 'America/Yellowknife', 'DrupalDateTime uses the specified timezone if provided.'); // Set a site timezone. - variable_set('date_default_timezone', 'Europe/Warsaw'); + config('system.date')->set('timezone.default', 'Europe/Warsaw')->save(); // Create a date object with an unspecified timezone, which should // end up using the site timezone. @@ -75,7 +75,7 @@ public function testDateTimezone() { $this->assertTrue($timezone == 'Europe/Warsaw', 'DrupalDateTime uses the site timezone if provided.'); // Create user. - variable_set('configurable_timezones', 1); + config('system.date')->set('timezone.user.configurable', 1)->save(); $test_user = $this->drupalCreateUser(array()); $this->drupalLogin($test_user); 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 10f49b9..172973d 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( @@ -57,20 +57,39 @@ function testLocalizeDateFormats() { ); $this->drupalPost('admin/config/regional/language/detection', $edit, t('Save settings')); + // Add new date format for French. + $edit = array( + 'date_format_id' => 'example_style_fr', + 'date_format_name' => 'Example Style', + 'date_format_pattern' => 'd.m.Y - H:i', + 'date_langcode[]' => array('fr'), + ); + $this->drupalPost('admin/config/regional/date-time/formats/add', $edit, t('Add format')); + + // Add new date format for English. + $edit = array( + 'date_format_id' => 'example_style_en', + 'date_format_name' => 'Example Style', + 'date_format_pattern' => 'j M Y - g:ia', + 'date_langcode[]' => array('en'), + ); + $this->drupalPost('admin/config/regional/date-time/formats/add', $edit, t('Add format')); + // Configure date formats. $this->drupalGet('admin/config/regional/date-time/locale'); $this->assertText('French', 'Configured languages appear.'); $edit = array( - 'date_format_long' => 'd.m.Y - H:i', - 'date_format_medium' => 'd.m.Y - H:i', - 'date_format_short' => 'd.m.Y - H:i', + 'date_format_system_long' => 'example_style_fr', + 'date_format_system_medium' => 'example_style_fr', + 'date_format_system_short' => 'example_style_fr', ); $this->drupalPost('admin/config/regional/date-time/locale/fr/edit', $edit, t('Save configuration')); $this->assertText(t('Configuration saved.'), 'French date formats updated.'); + $edit = array( - 'date_format_long' => 'j M Y - g:ia', - 'date_format_medium' => 'j M Y - g:ia', - 'date_format_short' => 'j M Y - g:ia', + 'date_format_system_long' => 'example_style_en', + 'date_format_system_medium' => 'example_style_en', + 'date_format_system_short' => 'example_style_en', ); $this->drupalPost('admin/config/regional/date-time/locale/en/edit', $edit, t('Save configuration')); $this->assertText(t('Configuration saved.'), 'English date formats updated.'); @@ -85,5 +104,10 @@ function testLocalizeDateFormats() { $this->drupalGet('fr/node/' . $node->nid); $french_date = format_date($node->created, 'custom', 'd.m.Y'); $this->assertText($french_date, 'French date format appears'); + + // Make sure we can reset dates back to default. + $this->drupalPost('admin/config/regional/date-time/locale/en/reset', array(), t('Reset')); + $this->drupalGet('node/' . $node->nid); + $this->assertNoText($english_date, 'English date format does not appear'); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/System/DateTimeTest.php b/core/modules/system/lib/Drupal/system/Tests/System/DateTimeTest.php index 8483da2..53dccbe 100644 --- a/core/modules/system/lib/Drupal/system/Tests/System/DateTimeTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/System/DateTimeTest.php @@ -38,15 +38,16 @@ function setUp() { $this->drupalLogin($this->admin_user); } - /** * Test time zones and DST handling. */ function testTimeZoneHandling() { // Setup date/time settings for Honolulu time. - variable_set('date_default_timezone', 'Pacific/Honolulu'); - variable_set('configurable_timezones', 0); - variable_set('date_format_medium', 'Y-m-d H:i:s O'); + $config = config('system.date') + ->set('timezone.default', 'Pacific/Honolulu') + ->set('timezone.user.configurable', 0) + ->set('formats.system_medium.pattern.php', 'Y-m-d H:i:s O') + ->save(); // Create some nodes with different authored-on dates. $date1 = '2007-01-31 21:00:00 -1000'; @@ -61,7 +62,7 @@ function testTimeZoneHandling() { $this->assertText('2007-07-31 21:00:00 -1000', 'Date should be identical, with GMT offset of -10 hours.'); // Set time zone to Los Angeles time. - variable_set('date_default_timezone', 'America/Los_Angeles'); + $config->set('timezone.default', 'America/Los_Angeles')->save(); // Confirm date format and time zone. $this->drupalGet("node/$node1->nid"); @@ -71,64 +72,33 @@ function testTimeZoneHandling() { } /** - * Test date type configuration. - */ - function testDateTypeConfiguration() { - // Confirm system date types appear. - $this->drupalGet('admin/config/regional/date-time'); - $this->assertText(t('Medium'), 'System date types appear in date type list.'); - $this->assertNoRaw('href="/admin/config/regional/date-time/types/medium/delete"', 'No delete link appear for system date types.'); - - // Add custom date type. - $this->clickLink(t('Add date type')); - $date_type = strtolower($this->randomName(8)); - $machine_name = 'machine_' . $date_type; - $date_format = 'd.m.Y - H:i'; - $edit = array( - 'date_type' => $date_type, - 'machine_name' => $machine_name, - 'date_format' => $date_format, - ); - $this->drupalPost('admin/config/regional/date-time/types/add', $edit, t('Add date type')); - $this->assertEqual($this->getUrl(), url('admin/config/regional/date-time', array('absolute' => TRUE)), 'Correct page redirection.'); - $this->assertText(t('New date type added successfully.'), 'Date type added confirmation message appears.'); - $this->assertText($date_type, 'Custom date type appears in the date type list.'); - $this->assertText(t('delete'), 'Delete link for custom date type appears.'); - - // Delete custom date type. - $this->clickLink(t('delete')); - $this->drupalPost('admin/config/regional/date-time/types/' . $machine_name . '/delete', array(), t('Remove')); - $this->assertEqual($this->getUrl(), url('admin/config/regional/date-time', array('absolute' => TRUE)), 'Correct page redirection.'); - $this->assertText(t('Removed date type ' . $date_type), 'Custom date type removed.'); - } - - /** * Test date format configuration. */ function testDateFormatConfiguration() { // Confirm 'no custom date formats available' message appears. $this->drupalGet('admin/config/regional/date-time/formats'); - $this->assertText(t('No custom date formats available.'), 'No custom date formats message appears.'); // Add custom date format. $this->clickLink(t('Add format')); + $date_format_id = strtolower($this->randomName(8)); + $name = ucwords($date_format_id); + $date_format = 'd.m.Y - H:i'; $edit = array( - 'date_format' => 'Y', + 'date_format_id' => $date_format_id, + 'date_format_name' => $name, + 'date_format_pattern' => $date_format, ); $this->drupalPost('admin/config/regional/date-time/formats/add', $edit, t('Add format')); $this->assertEqual($this->getUrl(), url('admin/config/regional/date-time/formats', array('absolute' => TRUE)), 'Correct page redirection.'); - $this->assertNoText(t('No custom date formats available.'), 'No custom date formats message does not appear.'); - $this->assertText(t('Custom date format added.'), 'Custom date format added.'); - - // Ensure custom date format appears in date type configuration options. - $this->drupalGet('admin/config/regional/date-time'); - $this->assertRaw('