Commit be694ba9 authored by webchick's avatar webchick

Issue #1571632 by cosmicdreams, marcingy, justafish, chx, KarenS, aspilicious,...

Issue #1571632 by cosmicdreams, marcingy, justafish, chx, KarenS, aspilicious, disasm, swentel, dawehner, rvilar: Convert regional settings to configuration system.
parent 7112165e
......@@ -2182,13 +2182,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();
}
}
......
......@@ -1827,11 +1827,11 @@ 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: '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.
* - The machine name of an administrator-defined date format.
* - 'custom', to use $format.
* Defaults to 'medium'.
......@@ -1871,66 +1871,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 medium if a format was not found.
if (empty($format)) {
$format = config('system.date')->get('formats.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);
}
/**
......
<?php
/**
* @file
* Initializes the list of date formats and their locales.
*/
/**
* Provides a default system list of date formats for system_date_formats().
*/
function system_default_date_formats() {
$formats = array();
// Short date formats.
$formats[] = array(
'type' => '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;
}
......@@ -3003,7 +3003,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.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'));
......
......@@ -1938,7 +1938,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,
......@@ -2011,8 +2011,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]) {
......
......@@ -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);
......
......@@ -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, 'medium');
}
$variables['categories'] = array();
......
......@@ -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'),
),
),
),
......
......@@ -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(
......@@ -97,8 +100,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(
......@@ -137,8 +143,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());
......@@ -187,7 +195,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('');
......@@ -226,7 +233,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(
......
first_day: '0'
country:
default: ''
timezone:
default: ''
user:
configurable: '1'
default: '0'
warn: '0'
formats:
long:
name: 'Default Long Date'
pattern:
php: 'l, F j, Y - H:i'
intl: 'EEEE, LLLL d, yyyy - kk:mm'
locked: 0
medium:
name: 'Default Medium Date'
pattern:
php: 'D, m/d/Y - H:i'
intl: 'ccc, MM/dd/yyyy - kk:mm'
locked: 0
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
......@@ -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.long.pattern.php', 'l, j. F Y - G:i')
->set('formats.medium.pattern.php', 'j. F Y - G:i')
->set('formats.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();
}
......@@ -56,17 +60,12 @@ function testAdminDefinedFormatDate() {
$this->drupalLogin($this->admin_user);
// 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' => 'j M y',
);
$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.');
......
......@@ -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);
......
......@@ -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_long' => 'example_style_fr',
'date_format_medium' => 'example_style_fr',
'date_format_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_long' => 'example_style_en',
'date_format_medium' => 'example_style_en',
'date_format_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');
}
}
......@@ -38,15 +38,16 @@ function setUp() {
$this->drupalLogin($this->admin_user);
}
/**
* Test time zones and DST handling.
*/
function testTimeZoneHandling() {