Skip to content

Commit de4dd6d

Browse files
authored
Merge pull request phpbb#6733 from marc1706/ticket/14404
[ticket/14404] Set board & admin timezone based on browser timezone
2 parents ae8a5e7 + 36de1a4 commit de4dd6d

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

phpBB/assets/javascript/installer.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,11 +605,29 @@
605605
function interceptFormSubmit($form) {
606606
if (!$form.length) {
607607
return;
608+
} else if ($form.find('input[name="admin_name"]').length > 0) {
609+
setAdminTimezone($form);
608610
}
609611

610612
$form.find(':submit').bind('click', function (event) {
611613
event.preventDefault();
612614
submitForm($form, $(this));
613615
});
614616
}
617+
618+
/**
619+
* Set admin timezone in form
620+
*
621+
* @param $form
622+
*/
623+
function setAdminTimezone($form) {
624+
// Set admin timezone if it does not exist yet
625+
if ($form.find('input[name="admin_timezone"]').length === 0) {
626+
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
627+
628+
// Add timezone as form entry
629+
const timezoneEntry = $('<input type="hidden" name="admin_timezone" value="' + timeZone + '">');
630+
$form.append(timezoneEntry);
631+
}
632+
}
615633
})(jQuery); // Avoid conflicts with other libraries

phpBB/phpbb/install/module/install_database/task/add_config_settings.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ public function run()
132132

133133
$updates = [
134134
'board_startdate' => (string) $current_time,
135+
'board_timezone' => $this->install_config->get('admin_timezone'),
135136
'default_lang' => $this->install_config->get('default_lang'),
136137

137138
'server_name' => $this->install_config->get('server_name'),

phpBB/phpbb/install/module/install_database/task/update_user_and_post_data.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ public function run()
114114
. ' user_lang = :lang,'
115115
. ' user_email = :email,'
116116
. ' user_dateformat = :dateformat,'
117-
. ' username_clean = :clean_username'
117+
. ' username_clean = :clean_username,'
118+
. ' user_timezone = :timezone'
118119
. ' WHERE username = \'Admin\'';
119120

120121
$this->create_and_execute_prepared_stmt($sql, [
@@ -125,6 +126,7 @@ public function run()
125126
'email' => $this->install_config->get('board_email'),
126127
'dateformat' => $this->language->lang('default_dateformat'),
127128
'clean_username' => utf8_clean_string($this->install_config->get('admin_name')),
129+
'timezone' => $this->install_config->get('admin_timezone'),
128130
]);
129131
$this->exec_sql('UPDATE ' . $this->user_table . ' SET user_regdate = ' . $current_time);
130132

phpBB/phpbb/install/module/obtain_data/task/obtain_admin_data.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ protected function process_form()
7171
$admin_pass1 = $this->io_handler->get_input('admin_pass1', '', true);
7272
$admin_pass2 = $this->io_handler->get_input('admin_pass2', '', true);
7373
$board_email = $this->io_handler->get_input('board_email', '', true);
74+
$admin_timezone = $this->io_handler->get_input('admin_timezone', 'UTC', true);
7475

7576
$admin_data_valid = $this->check_admin_data($admin_name, $admin_pass1, $admin_pass2, $board_email);
7677

@@ -79,6 +80,7 @@ protected function process_form()
7980
$this->install_config->set('admin_name', $admin_name);
8081
$this->install_config->set('admin_passwd', $admin_pass1);
8182
$this->install_config->set('board_email', $board_email);
83+
$this->install_config->set('admin_timezone', $admin_timezone);
8284
}
8385
else
8486
{

0 commit comments

Comments
 (0)