1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-28 08:20:57 +01:00

Add timezone support

Summary:
Allows user-configurable timezones. Adds a preference panel, and migrates to the
new date rendering in easily-modified areas of the code. ***In progress***.

Test Plan:
Check database to make sure the field is being changed when the settings are
changed; check affected views to see how they render times.

Reviewed By: epriestley
Reviewers: epriestley
CC: aran, epriestley, toulouse
Differential Revision: 475
This commit is contained in:
Andrew Toulouse 2011-06-18 13:07:02 -07:00
parent 565cc43f27
commit 9b522982fa
20 changed files with 71 additions and 13 deletions

View file

@ -0,0 +1,2 @@
ALTER TABLE phabricator_user.user
ADD timezoneIdentifier varchar(255) NOT NULL DEFAULT "America/Los_Angeles";

View file

@ -539,10 +539,13 @@ phutil_register_library_map(array(
'celerity_generate_unique_node_id' => 'infrastructure/celerity/api',
'celerity_register_resource_map' => 'infrastructure/celerity/map',
'javelin_render_tag' => 'infrastructure/javelin/markup',
'phabricator_date' => 'view/utils',
'phabricator_datetime' => 'view/utils',
'phabricator_format_relative_time' => 'view/utils',
'phabricator_format_timestamp' => 'view/utils',
'phabricator_format_units_generic' => 'view/utils',
'phabricator_render_form' => 'infrastructure/javelin/markup',
'phabricator_time' => 'view/utils',
'qsprintf' => 'storage/qsprintf',
'queryfx' => 'storage/queryfx',
'queryfx_all' => 'storage/queryfx',

View file

@ -23,6 +23,7 @@ class DiffusionCommitController extends DiffusionController {
public function processRequest() {
$drequest = $this->getDiffusionRequest();
$request = $this->getRequest();
$user = $request->getUser();
$callsign = $drequest->getRepository()->getCallsign();
@ -56,7 +57,7 @@ class DiffusionCommitController extends DiffusionController {
'<div class="diffusion-commit-dateline">'.
'r'.$callsign.$commit->getCommitIdentifier().
' &middot; '.
date('F jS, Y g:i A', $commit->getEpoch()).
phabricator_datetime($commit->getEpoch(), $user).
'</div>'.
'<h1>Revision Detail</h1>'.
'<div class="diffusion-commit-details">'.

View file

@ -20,6 +20,7 @@ phutil_require_module('phabricator', 'infrastructure/celerity/api');
phutil_require_module('phabricator', 'storage/queryfx');
phutil_require_module('phabricator', 'view/form/error');
phutil_require_module('phabricator', 'view/layout/panel');
phutil_require_module('phabricator', 'view/utils');
phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'utils');

View file

@ -19,6 +19,8 @@
class DiffusionHomeController extends DiffusionController {
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$shortcuts = id(new PhabricatorRepositoryShortcut())->loadAll();
if ($shortcuts) {
@ -94,8 +96,8 @@ class DiffusionHomeController extends DiffusionController {
$date = '-';
$time = '-';
if ($commit) {
$date = date('M j, Y', $commit->getEpoch());
$time = date('g:i A', $commit->getEpoch());
$date = phabricator_date($commit->getEpoch(), $user);
$time = phabricator_time($commit->getEpoch(), $user);
}
$rows[] = array(

View file

@ -15,6 +15,7 @@ phutil_require_module('phabricator', 'applications/repository/storage/shortcut')
phutil_require_module('phabricator', 'storage/queryfx');
phutil_require_module('phabricator', 'view/control/table');
phutil_require_module('phabricator', 'view/layout/panel');
phutil_require_module('phabricator', 'view/utils');
phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'utils');

View file

@ -21,6 +21,7 @@ class HeraldTranscriptListController extends HeraldController {
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
// Get one page of data together with the pager.
// Pull these objects manually since the serialized fields are gigantic.
@ -98,8 +99,8 @@ class HeraldTranscriptListController extends HeraldController {
$rows = array();
foreach ($data as $xscript) {
$rows[] = array(
date('F jS', $xscript['time']),
date('g:i:s A', $xscript['time']),
phabricator_date($xscript['time'],$user),
phabricator_time($xscript['time'],$user),
$handles[$xscript['objectPHID']]->renderLink(),
$xscript['dryRun'] ? 'Yes' : '',
number_format((int)(1000 * $xscript['duration'])).' ms',

View file

@ -14,6 +14,7 @@ phutil_require_module('phabricator', 'storage/queryfx');
phutil_require_module('phabricator', 'view/control/pager');
phutil_require_module('phabricator', 'view/control/table');
phutil_require_module('phabricator', 'view/layout/panel');
phutil_require_module('phabricator', 'view/utils');
phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'utils');

View file

@ -22,6 +22,7 @@ class PhabricatorMetaMTAReceivedListController
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$pager = new AphrontPagerView();
$pager->setOffset($request->getInt('page'));
@ -45,8 +46,8 @@ class PhabricatorMetaMTAReceivedListController
foreach ($mails as $mail) {
$rows[] = array(
$mail->getID(),
date('M jS Y', $mail->getDateCreated()),
date('g:i:s A', $mail->getDateCreated()),
phabricator_date($mail->getDateCreated(), $user),
phabricator_time($mail->getDateCreated(), $user),
$mail->getAuthorPHID()
? $handles[$mail->getAuthorPHID()]->renderLink()
: '-',

View file

@ -12,6 +12,7 @@ phutil_require_module('phabricator', 'applications/phid/handle/data');
phutil_require_module('phabricator', 'view/control/pager');
phutil_require_module('phabricator', 'view/control/table');
phutil_require_module('phabricator', 'view/layout/panel');
phutil_require_module('phabricator', 'view/utils');
phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'utils');

View file

@ -27,6 +27,7 @@ class PhabricatorMetaMTAViewController extends PhabricatorMetaMTAController {
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$mail = id(new PhabricatorMetaMTAMail())->load($this->id);
if (!$mail) {
@ -46,7 +47,7 @@ class PhabricatorMetaMTAViewController extends PhabricatorMetaMTAController {
->appendChild(
id(new AphrontFormStaticControl())
->setLabel('Created')
->setValue(date('F jS, Y g:i:s A', $mail->getDateCreated())))
->setValue(phabricator_datetime($mail->getDateCreated(), $user)))
->appendChild(
id(new AphrontFormStaticControl())
->setLabel('Status')

View file

@ -14,6 +14,7 @@ phutil_require_module('phabricator', 'view/form/control/static');
phutil_require_module('phabricator', 'view/form/control/submit');
phutil_require_module('phabricator', 'view/form/control/textarea');
phutil_require_module('phabricator', 'view/layout/panel');
phutil_require_module('phabricator', 'view/utils');
phutil_require_module('phutil', 'utils');

View file

@ -53,8 +53,8 @@ class PhabricatorPeopleListController extends PhabricatorPeopleController {
}
$rows[] = array(
date('M jS, Y', $user->getDateCreated()),
date('g:i:s A', $user->getDateCreated()),
phabricator_date($user->getDateCreated(), $user),
phabricator_time($user->getDateCreated(), $user),
phutil_render_tag(
'a',
array(

View file

@ -12,6 +12,7 @@ phutil_require_module('phabricator', 'storage/queryfx');
phutil_require_module('phabricator', 'view/control/pager');
phutil_require_module('phabricator', 'view/control/table');
phutil_require_module('phabricator', 'view/layout/panel');
phutil_require_module('phabricator', 'view/utils');
phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'utils');

View file

@ -169,8 +169,8 @@ class PhabricatorPeopleLogsController extends PhabricatorPeopleController {
$rows = array();
foreach ($logs as $log) {
$rows[] = array(
date('M jS, Y', $log->getDateCreated()),
date('g:i:s A', $log->getDateCreated()),
phabricator_date($log->getDateCreated(),$user),
phabricator_time($log->getDateCreated(),$user),
$log->getAction(),
$log->getActorPHID()
? phutil_escape_html($handles[$log->getActorPHID()]->getName())

View file

@ -19,6 +19,7 @@ phutil_require_module('phabricator', 'view/form/control/text');
phutil_require_module('phabricator', 'view/form/control/tokenizer');
phutil_require_module('phabricator', 'view/layout/listfilter');
phutil_require_module('phabricator', 'view/layout/panel');
phutil_require_module('phabricator', 'view/utils');
phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'utils');

View file

@ -137,6 +137,14 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
$e_realname = 'Required';
}
$new_timezone = $request->getStr('timezone');
if (in_array($new_timezone, DateTimeZone::listIdentifiers(), true)) {
$user->setTimezoneIdentifier($new_timezone);
} else {
$errors[] =
'The selected timezone is not a valid timezone.';
}
if (!$errors) {
$user->save();
@ -324,6 +332,9 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
))));
if ($editable) {
$timezone_ids = DateTimeZone::listIdentifiers();
$timezone_id_map = array_combine($timezone_ids, $timezone_ids);
$form
->appendChild(
id(new AphrontFormFileControl())
@ -333,6 +344,15 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
->appendChild(
id(new AphrontFormMarkupControl())
->setValue('<hr />'))
->appendChild(
id(new AphrontFormSelectControl())
->setLabel('Timezone')
->setName('timezone')
->setOptions($timezone_id_map)
->setValue($user->getTimezoneIdentifier()))
->appendChild(
id(new AphrontFormMarkupControl())
->setValue('<hr />'))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue('Save'));
@ -534,4 +554,4 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
return $notice.$panel->render();
}
}
}

View file

@ -22,6 +22,7 @@ phutil_require_module('phabricator', 'view/dialog');
phutil_require_module('phabricator', 'view/form/base');
phutil_require_module('phabricator', 'view/form/control/file');
phutil_require_module('phabricator', 'view/form/control/markup');
phutil_require_module('phabricator', 'view/form/control/select');
phutil_require_module('phabricator', 'view/form/control/static');
phutil_require_module('phabricator', 'view/form/control/submit');
phutil_require_module('phabricator', 'view/form/control/text');

View file

@ -27,6 +27,7 @@ class PhabricatorUser extends PhabricatorUserDAO {
protected $passwordSalt;
protected $passwordHash;
protected $profileImagePHID;
protected $timezoneIdentifier;
protected $consoleEnabled = 0;
protected $consoleVisible = 0;

View file

@ -16,6 +16,24 @@
* limitations under the License.
*/
function phabricator_date($epoch, $user) {
$zone = new DateTimeZone($user->getTimezoneIdentifier());
$date = new DateTime('@'.$epoch, $zone);
return $date->format('M j Y');
}
function phabricator_time($epoch, $user) {
$zone = new DateTimeZone($user->getTimezoneIdentifier());
$date = new DateTime('@'.$epoch, $zone);
return $date->format('g:i A');
}
function phabricator_datetime($epoch, $user) {
$zone = new DateTimeZone($user->getTimezoneIdentifier());
$date = new DateTime('@'.$epoch, $zone);
return $date->format('M j Y, g:i A');
}
function phabricator_format_relative_time($duration) {
return phabricator_format_units_generic(
$duration,