Commit ab200662 authored by catch's avatar catch

Issue #1858984 by berdir: Split system date formats from timezone settings.

parent 38310221
......@@ -2195,15 +2195,15 @@ function drupal_bootstrap($phase = NULL, $new_phase = TRUE) {
*/
function drupal_get_user_timezone() {
global $user;
$config = config('system.date');
$config = config('system.timezone');
if ($config->get('timezone.user.configurable') && $user->uid && $user->timezone) {
if ($config->get('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.
$config_data_default_timezone = $config->get('timezone.default');
$config_data_default_timezone = $config->get('default');
return !empty($config_data_default_timezone) ? $config_data_default_timezone : @date_default_timezone_get();
}
}
......
......@@ -2006,8 +2006,11 @@ function install_configure_form_submit($form, &$form_state) {
->set('mail', $form_state['values']['site_mail'])
->save();
config('system.timezone')
->set('default', $form_state['values']['date_default_timezone'])
->save();
config('system.date')
->set('timezone.default', $form_state['values']['date_default_timezone'])
->set('country.default', $form_state['values']['site_default_country'])
->save();
......
......@@ -42,9 +42,9 @@ function setUp() {
function testRegisterUserWithEmailVerification() {
config('user.settings')->set('verify_mail', TRUE)->save();
config('system.date')
->set('timezone.user.configurable', 1)
->set('timezone.default', 'Europe/Brussels')
config('system.timezone')
->set('user.configurable', 1)
->set('default', 'Europe/Brussels')
->save();
// Tell openid_test.module to respond with these SREG fields.
......@@ -101,9 +101,9 @@ function testRegisterUserWithEmailVerification() {
function testRegisterUserWithoutEmailVerification() {
config('user.settings')->set('verify_mail', FALSE)->save();
config('system.date')
->set('timezone.user.configurable', 1)
->set('timezone.default', 'Europe/Brussels')
config('system.timezone')
->set('user.configurable', 1)
->set('default', 'Europe/Brussels')
->save();
// Tell openid_test.module to respond with these SREG fields.
......@@ -143,9 +143,9 @@ function testRegisterUserWithoutEmailVerification() {
* information (a username that is already taken, and no e-mail address).
*/
function testRegisterUserWithInvalidSreg() {
config('system.date')
->set('timezone.user.configurable', 1)
->set('timezone.default', 'Europe/Brussels')
config('system.timezone')
->set('user.configurable', 1)
->set('default', 'Europe/Brussels')
->save();
// Tell openid_test.module to respond with these SREG fields.
......@@ -233,8 +233,8 @@ function testRegisterUserWithoutSreg() {
*/
function testRegisterUserWithAXButNoSREG() {
config('user.settings')->set('verify_mail', FALSE)->save();
config('system.date')
->set('timezone.default', 'Europe/Brussels')
config('system.timezone')
->set('default', 'Europe/Brussels')
->save();
// Tell openid_test.module to respond with these AX fields.
......
first_day: '0'
country:
default: ''
timezone:
default: ''
user:
configurable: '1'
default: '0'
warn: '0'
formats:
long:
name: 'Default Long Date'
......
default: ''
user:
configurable: '1'
default: '0'
warn: '0'
......@@ -36,8 +36,10 @@ public static function getInfo() {
function setUp() {
parent::setUp('language');
config('system.timezone')
->set('user.configurable', 1)
->save();
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')
......
......@@ -48,8 +48,10 @@ public function testDateTimezone() {
$date_string = '2007-01-31 21:00:00';
// Make sure no site timezone has been set.
config('system.date')->set('timezone.default', NULL)->save();
config('system.date')->set('timezone.user.configurable', 0)->save();
config('system.timezone')
->set('user.configurable', 0)
->set('default', NULL)
->save();
// Detect the system timezone.
$system_timezone = date_default_timezone_get();
......@@ -66,7 +68,7 @@ public function testDateTimezone() {
$this->assertTrue($timezone == 'America/Yellowknife', 'DrupalDateTime uses the specified timezone if provided.');
// Set a site timezone.
config('system.date')->set('timezone.default', 'Europe/Warsaw')->save();
config('system.timezone')->set('default', 'Europe/Warsaw')->save();
// Create a date object with an unspecified timezone, which should
// end up using the site timezone.
......@@ -75,7 +77,7 @@ public function testDateTimezone() {
$this->assertTrue($timezone == 'Europe/Warsaw', 'DrupalDateTime uses the site timezone if provided.');
// Create user.
config('system.date')->set('timezone.user.configurable', 1)->save();
config('system.timezone')->set('user.configurable', 1)->save();
$test_user = $this->drupalCreateUser(array());
$this->drupalLogin($test_user);
......
......@@ -43,9 +43,11 @@ function setUp() {
*/
function testTimeZoneHandling() {
// Setup date/time settings for Honolulu time.
$config = config('system.date')
->set('timezone.default', 'Pacific/Honolulu')
->set('timezone.user.configurable', 0)
$config = config('system.timezone')
->set('default', 'Pacific/Honolulu')
->set('user.configurable', 0)
->save();
config('system.date')
->set('formats.medium.pattern.php', 'Y-m-d H:i:s O')
->save();
......@@ -62,7 +64,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.
$config->set('timezone.default', 'America/Los_Angeles')->save();
$config->set('default', 'America/Los_Angeles')->save();
// Confirm date format and time zone.
$this->drupalGet("node/$node1->nid");
......
......@@ -1866,7 +1866,7 @@ function system_rss_feeds_settings_submit($form, &$form_state) {
*/
function system_regional_settings($form, &$form_state) {
$countries = country_get_list();
$system_date = config('system.date');
$system_timezone = config('system.timezone');
$system_date = config('system.date');
// Date settings:
......@@ -1898,16 +1898,14 @@ function system_regional_settings($form, &$form_state) {
'#title' => t('Time zones'),
);
$date_default_timezone = $system_date->get('timezone.default');
$date_default_timezone = $system_date->get('timezone.default');
$form['timezone']['date_default_timezone'] = array(
'#type' => 'select',
'#title' => t('Default time zone'),
'#default_value' => isset($date_default_timezone) ? $date_default_timezone : date_default_timezone_get(),
'#default_value' => $system_timezone->get('default') ?: date_default_timezone_get(),
'#options' => $zones,
);
$configurable_timezones = $system_date->get('timezone.user.configurable');
$configurable_timezones = $system_timezone->get('user.configurable');
$form['timezone']['configurable_timezones'] = array(
'#type' => 'checkbox',
'#title' => t('Users may set their own time zone.'),
......@@ -1927,14 +1925,14 @@ function system_regional_settings($form, &$form_state) {
$form['timezone']['configurable_timezones_wrapper']['empty_timezone_message'] = array(
'#type' => 'checkbox',
'#title' => t('Remind users at login if their time zone is not set.'),
'#default_value' => $system_date->get('timezone.user.warn'),
'#default_value' => $system_timezone->get('user.warn'),
'#description' => t('Only applied if users may set their own time zone.')
);
$form['timezone']['configurable_timezones_wrapper']['user_default_timezone'] = array(
'#type' => 'radios',
'#title' => t('Time zone for new users'),
'#default_value' => $system_date->get('timezone.user.default'),
'#default_value' => $system_timezone->get('user.default'),
'#options' => array(
DRUPAL_USER_TIMEZONE_DEFAULT => t('Default time zone.'),
DRUPAL_USER_TIMEZONE_EMPTY => t('Empty time zone.'),
......@@ -1956,10 +1954,12 @@ function system_regional_settings_submit($form, &$form_state) {
config('system.date')
->set('country.default', $form_state['values']['site_default_country'])
->set('first_day', $form_state['values']['date_first_day'])
->set('timezone.default', $form_state['values']['date_default_timezone'])
->set('timezone.user.configurable', $form_state['values']['configurable_timezones'])
->set('timezone.user.warn', $form_state['values']['empty_timezone_message'])
->set('timezone.user.default', $form_state['values']['user_default_timezone'])
->save();
config('system.timezone')
->set('default', $form_state['values']['date_default_timezone'])
->set('user.configurable', $form_state['values']['configurable_timezones'])
->set('user.warn', $form_state['values']['empty_timezone_message'])
->set('user.default', $form_state['values']['user_default_timezone'])
->save();
}
......
......@@ -2286,9 +2286,12 @@ function system_update_8038() {
'site_default_country' => 'country.default',
'date_first_day' => 'first_day',
'date_default_timezone' => 'timezone.default',
'configurable_timezones' => 'timezone.user.configurable',
'empty_timezone_message' => 'timezone.user.warn',
'user_default_timezone' => 'timezone.user.default',
));
update_variables_to_config('system.timezone', array(
'date_default_timezone' => 'default',
'configurable_timezones' => 'user.configurable',
'empty_timezone_message' => 'user.warn',
'user_default_timezone' => 'user.default',
));
}
......
......@@ -2403,7 +2403,7 @@ function system_custom_theme() {
* Implements hook_form_FORM_ID_alter().
*/
function system_form_user_profile_form_alter(&$form, &$form_state) {
if (config('system.date')->get('timezone.user.configurable')) {
if (config('system.timezone')->get('user.configurable')) {
system_user_timezone($form, $form_state);
}
return $form;
......@@ -2413,8 +2413,8 @@ function system_form_user_profile_form_alter(&$form, &$form_state) {
* Implements hook_form_FORM_ID_alter().
*/
function system_form_user_register_form_alter(&$form, &$form_state) {
$config = config('system.date');
if ($config->get('timezone.user.configurable') && $config->get('timezone.user.default') == DRUPAL_USER_TIMEZONE_SELECT) {
$config = config('system.timezone');
if ($config->get('user.configurable') && $config->get('user.default') == DRUPAL_USER_TIMEZONE_SELECT) {
system_user_timezone($form, $form_state);
return $form;
}
......@@ -2424,9 +2424,9 @@ function system_form_user_register_form_alter(&$form, &$form_state) {
* Implements hook_user_presave().
*/
function system_user_presave($account) {
$config = config('system.date');
if ($config->get('timezone.user.configurable') && empty($account->timezone) && !$config->get('timezone.user.default')) {
$account->timezone = $config->get('timezone.default');
$config = config('system.timezone');
if ($config->get('user.configurable') && empty($account->timezone) && !$config->get('user.default')) {
$account->timezone = $config->get('default');
}
}
......@@ -2434,9 +2434,9 @@ function system_user_presave($account) {
* Implements hook_user_login().
*/
function system_user_login($edit, $account) {
$config = config('system.date');
$config = config('system.timezone');
// 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')) {
if (!$account->timezone && $config->get('user.configurable') && $config->get('user.warn')) {
drupal_set_message(t('Configure your <a href="@user-edit">account time zone setting</a>.', array('@user-edit' => url("user/$account->uid/edit", array('query' => drupal_get_destination(), 'fragment' => 'edit-timezone')))));
}
}
......
......@@ -157,9 +157,9 @@ function testRegistrationDefaultValues() {
->save();
// Set the default timezone to Brussels.
$config_system_date = config('system.date')
->set('timezone.user.configurable', 1)
->set('timezone.default', 'Europe/Brussels')
$config_system_timezone = config('system.timezone')
->set('user.configurable', 1)
->set('default', 'Europe/Brussels')
->save();
// Check that the account information options are not displayed
......@@ -183,7 +183,7 @@ function testRegistrationDefaultValues() {
$this->assertEqual($new_user->signature, '', 'Correct signature field.');
$this->assertTrue(($new_user->created > REQUEST_TIME - 20 ), 'Correct creation time.');
$this->assertEqual($new_user->status, $config_user_settings->get('register') == USER_REGISTER_VISITORS ? 1 : 0, 'Correct status field.');
$this->assertEqual($new_user->timezone, $config_system_date->get('timezone.default'), 'Correct time zone field.');
$this->assertEqual($new_user->timezone, $config_system_timezone->get('default'), 'Correct time zone field.');
$this->assertEqual($new_user->langcode, language_default()->langcode, 'Correct language field.');
$this->assertEqual($new_user->preferred_langcode, language_default()->langcode, 'Correct preferred language field.');
$this->assertEqual($new_user->init, $mail, 'Correct init field.');
......
......@@ -26,9 +26,11 @@ public static function getInfo() {
*/
function testUserTimeZone() {
// Setup date/time settings for Los Angeles time.
$config = config('system.date')
->set('timezone.user.configurable', 1)
->set('timezone.default', 'America/Los_Angeles')
config('system.timezone')
->set('user.configurable', 1)
->set('default', 'America/Los_Angeles')
->save();
config('system.date')
->set('formats.medium.pattern.php', 'Y-m-d H:i T')
->save();
......
......@@ -305,9 +305,9 @@ function hook_user_update($account) {
* The user object on which the operation was just performed.
*/
function hook_user_login(&$edit, $account) {
$config = config('system.date');
$config = config('system.timezone');
// 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')) {
if (!$account->timezone && $config->get('user.configurable') && $config->get('user.warn')) {
drupal_set_message(t('Configure your <a href="@user-edit">account time zone setting</a>.', array('@user-edit' => url("user/$account->uid/edit", array('query' => drupal_get_destination(), 'fragment' => 'edit-timezone')))));
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment