diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index de6a4ef..0bba986 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2161,13 +2161,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 isset($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 d0e9a2f..24b14dc 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -1920,58 +1920,14 @@ 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; - - case 'custom': - // No change to format. - break; - - 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; + // Handle the base case: $type == 'custom' + // if $type is custom use the format that is provided by the $format argument + if ($type != 'custom') { + $format = config('system.date')->get('formats.' . $type . '.pattern'); + if (!isset($format)) { + // If that type didn't exist return format medium's value + $format = config('system.date')->get('formats.system_medium.pattern'); + } } // Create a DateTime object from the timestamp. diff --git a/core/includes/form.inc b/core/includes/form.inc index 5f580fb..8abac99 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -2953,7 +2953,7 @@ 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.sytem_short.pattern'); $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 81b9b6a..8efd087 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -1908,7 +1908,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, @@ -1974,8 +1974,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/modules/aggregator/aggregator.pages.inc b/core/modules/aggregator/aggregator.pages.inc index 78ca5bc..15ed9bd 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, 'custom', config('system.date')->get('formats.system_medium.pattern')); } $variables['categories'] = array(); diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index a32d47d..b069a9e 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -503,7 +503,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/openid/lib/Drupal/openid/Tests/OpenIDRegistrationTest.php b/core/modules/openid/lib/Drupal/openid/Tests/OpenIDRegistrationTest.php index d556309..0e29aab 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 @@ class OpenIDRegistrationTest extends OpenIDTestBase { */ 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 @@ class OpenIDRegistrationTest extends OpenIDTestBase { */ 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 @@ class OpenIDRegistrationTest extends OpenIDTestBase { * 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 @@ class OpenIDRegistrationTest extends OpenIDTestBase { * 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 @@ class OpenIDRegistrationTest extends OpenIDTestBase { */ 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/system/lib/Drupal/system/Tests/Common/FormatDateTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php index 9639758..b850ba4 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 @@ class FormatDateTest extends WebTestBase { } 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', 'l, j. F Y - G:i') + ->set('formats.system_medium.pattern', 'j. F Y - G:i') + ->set('formats.system_short.pattern', '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,16 +61,12 @@ class FormatDateTest extends WebTestBase { // 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, t('Add format')); - - // Add new date type. $edit = array( - 'date_type' => 'Example Style', - 'machine_name' => 'example_style', - 'date_format' => $admin_date_format, + 'dfid' => 'example_style', + 'date_format_name' => 'Example Style', + 'date_format_pattern' => $admin_date_format, ); - $this->drupalPost('admin/config/regional/date-time/types/add', $edit, t('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', t('Test format_date() using an admin-defined date type.')); 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 6494a4a..a1db7c4 100644 --- a/core/modules/system/lib/Drupal/system/Tests/System/DateTimeTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/System/DateTimeTest.php @@ -44,9 +44,11 @@ class DateTimeTest extends WebTestBase { */ 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', '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 +63,7 @@ class DateTimeTest extends WebTestBase { $this->assertText('2007-07-31 21:00:00 -1000', t('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 +73,35 @@ class DateTimeTest extends WebTestBase { } /** - * Test date type configuration. + * Test date format configuration. */ - function testDateTypeConfiguration() { + function testDateFormatConfiguration() { // 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)), t('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)), t('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')); + $dfid = strtolower($this->randomName(8)); + $name = ucwords($dfid); + $date_format = 'd.m.Y - H:i'; $edit = array( - 'date_format' => 'Y', + 'dfid' => $dfid, + '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)), t('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('