1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-19 16:58:48 +02:00

When the JS "Intl" API is available, use it to guess the timezone

Summary:
Ref T3025. Chrome gives us an easily-accessible, much better guess at which timezone the user is in.

Firefox also exposes "Intl" but this doesn't seem to be a reliable method to read the timezone.

Test Plan:
In Chrome, swapped my system date/time between zones, clicked the "reconcile" popup, got the dropdown prefilled accurately.

In Safari (no `Intl` API) got the normal flow with no default selected.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T3025

Differential Revision: https://secure.phabricator.com/D15962
This commit is contained in:
epriestley 2016-05-22 06:50:12 -07:00
parent 5d30ea56cf
commit 2a00f185eb
3 changed files with 29 additions and 9 deletions

View file

@ -8,7 +8,7 @@
return array(
'names' => array(
'core.pkg.css' => '8aeacc63',
'core.pkg.js' => '7b44c14f',
'core.pkg.js' => '50e9228e',
'darkconsole.pkg.js' => 'e7393ebb',
'differential.pkg.css' => '33da0633',
'differential.pkg.js' => '4b7d8f19',
@ -477,7 +477,7 @@ return array(
'rsrc/js/core/behavior-choose-control.js' => '327a00d1',
'rsrc/js/core/behavior-crop.js' => 'fa0f4fc2',
'rsrc/js/core/behavior-dark-console.js' => 'f411b6ae',
'rsrc/js/core/behavior-detect-timezone.js' => 'ae9f2ec9',
'rsrc/js/core/behavior-detect-timezone.js' => '4c193c96',
'rsrc/js/core/behavior-device.js' => 'bb1dd507',
'rsrc/js/core/behavior-drag-and-drop-textarea.js' => '484a6e22',
'rsrc/js/core/behavior-error-log.js' => '6882e80a',
@ -602,7 +602,7 @@ return array(
'javelin-behavior-dashboard-tab-panel' => 'd4eecc63',
'javelin-behavior-day-view' => '5c46cff2',
'javelin-behavior-desktop-notifications-control' => 'edd1ba66',
'javelin-behavior-detect-timezone' => 'ae9f2ec9',
'javelin-behavior-detect-timezone' => '4c193c96',
'javelin-behavior-device' => 'bb1dd507',
'javelin-behavior-differential-add-reviewers-and-ccs' => 'e10f8e18',
'javelin-behavior-differential-comment-jump' => '4fdb476d',
@ -1226,6 +1226,11 @@ return array(
'javelin-util',
'phabricator-shaped-request',
),
'4c193c96' => array(
'javelin-behavior',
'javelin-uri',
'phabricator-notification',
),
'4e3e79a6' => array(
'javelin-behavior',
'javelin-stratcom',
@ -1744,11 +1749,6 @@ return array(
'javelin-util',
'phabricator-busy',
),
'ae9f2ec9' => array(
'javelin-behavior',
'javelin-uri',
'phabricator-notification',
),
'b003d4fb' => array(
'javelin-behavior',
'javelin-stratcom',

View file

@ -74,12 +74,20 @@ final class PhabricatorSettingsTimezoneController
->addCancelButton('/', pht('Done'));
}
// If we have a guess at the timezone from the client, select it as the
// default.
$guess = $request->getStr('guess');
if (empty($options[$guess])) {
$guess = 'ignore';
}
$form = id(new AphrontFormView())
->appendChild(
id(new AphrontFormSelectControl())
->setName('timezone')
->setLabel(pht('Timezone'))
->setOptions($options));
->setOptions($options)
->setValue($guess));
return $this->newDialog()
->setTitle(pht('Adjust Timezone'))

View file

@ -45,6 +45,18 @@ JX.behavior('detect-timezone', function(config) {
var uri = config.uri + offset + '/';
// Some browsers (notably, Chrome) expose an "Intl" API which gives us
// direct access to a timezone setting. If we are able to read this, use
// it to guess which timezone the user is in so we can prefill the
// dropdown.
try {
var guess = Intl.DateTimeFormat().resolvedOptions().timeZone;
uri = JX.$U(uri).setQueryParam('guess', guess);
} catch (error) {
// Ignore any errors here, we'll just make the user pick from the big
// list.
}
new JX.Workflow(uri)
.start();
});