1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 08:42:41 +01:00

Use phabricator_ time functions in more places

Summary:
Replace some more date() calls with locale-aware calls.

Also, at least on my system, the DateTimeZone / DateTime stuff didn't actually
work and always rendered in UTC. Fixed that.

Test Plan:
Viewed daemon console, differential revisions, files, and maniphest timestamps
in multiple timezones.

Reviewed By: toulouse
Reviewers: toulouse, fratrik, jungejason, aran, tuomaspelkonen
CC: aran, toulouse
Differential Revision: 530
This commit is contained in:
epriestley 2011-06-26 09:22:52 -07:00
parent 0245b6cdf7
commit 74d57b0a42
26 changed files with 126 additions and 36 deletions

View file

@ -893,7 +893,7 @@ celerity_register_resource_map(array(
),
'maniphest-task-summary-css' =>
array(
'uri' => '/res/41624cb0/rsrc/css/application/maniphest/task-summary.css',
'uri' => '/res/0bacdd7f/rsrc/css/application/maniphest/task-summary.css',
'type' => 'css',
'requires' =>
array(
@ -1057,7 +1057,7 @@ celerity_register_resource_map(array(
),
'phabricator-remarkup-css' =>
array(
'uri' => '/res/d7e98209/rsrc/css/core/remarkup.css',
'uri' => '/res/e0c44a00/rsrc/css/core/remarkup.css',
'type' => 'css',
'requires' =>
array(
@ -1132,7 +1132,7 @@ celerity_register_resource_map(array(
'uri' => '/res/pkg/2892314d/typeahead.pkg.js',
'type' => 'js',
),
'd752b5da' =>
'cfafcff7' =>
array (
'name' => 'core.pkg.css',
'symbols' =>
@ -1153,7 +1153,7 @@ celerity_register_resource_map(array(
13 => 'phabricator-remarkup-css',
14 => 'syntax-highlighting-css',
),
'uri' => '/res/pkg/d752b5da/core.pkg.css',
'uri' => '/res/pkg/cfafcff7/core.pkg.css',
'type' => 'css',
),
'da416e1c' =>
@ -1225,15 +1225,15 @@ celerity_register_resource_map(array(
),
'reverse' =>
array (
'aphront-crumbs-view-css' => 'd752b5da',
'aphront-dialog-view-css' => 'd752b5da',
'aphront-form-view-css' => 'd752b5da',
'aphront-list-filter-view-css' => 'd752b5da',
'aphront-panel-view-css' => 'd752b5da',
'aphront-side-nav-view-css' => 'd752b5da',
'aphront-table-view-css' => 'd752b5da',
'aphront-tokenizer-control-css' => 'd752b5da',
'aphront-typeahead-control-css' => 'd752b5da',
'aphront-crumbs-view-css' => 'cfafcff7',
'aphront-dialog-view-css' => 'cfafcff7',
'aphront-form-view-css' => 'cfafcff7',
'aphront-list-filter-view-css' => 'cfafcff7',
'aphront-panel-view-css' => 'cfafcff7',
'aphront-side-nav-view-css' => 'cfafcff7',
'aphront-table-view-css' => 'cfafcff7',
'aphront-tokenizer-control-css' => 'cfafcff7',
'aphront-typeahead-control-css' => 'cfafcff7',
'differential-changeset-view-css' => '55967526',
'differential-core-view-css' => '55967526',
'differential-revision-add-comment-css' => '55967526',
@ -1270,13 +1270,13 @@ celerity_register_resource_map(array(
'javelin-util' => 'db95a6d0',
'javelin-vector' => 'db95a6d0',
'javelin-workflow' => 'f1d27e2a',
'phabricator-core-buttons-css' => 'd752b5da',
'phabricator-core-css' => 'd752b5da',
'phabricator-directory-css' => 'd752b5da',
'phabricator-core-buttons-css' => 'cfafcff7',
'phabricator-core-css' => 'cfafcff7',
'phabricator-directory-css' => 'cfafcff7',
'phabricator-keyboard-shortcut' => 'f1d27e2a',
'phabricator-keyboard-shortcut-manager' => 'f1d27e2a',
'phabricator-remarkup-css' => 'd752b5da',
'phabricator-standard-page-view' => 'd752b5da',
'syntax-highlighting-css' => 'd752b5da',
'phabricator-remarkup-css' => 'cfafcff7',
'phabricator-standard-page-view' => 'cfafcff7',
'syntax-highlighting-css' => 'cfafcff7',
),
));

View file

@ -37,6 +37,7 @@ class PhabricatorDaemonCombinedLogController
$event_view = new PhabricatorDaemonLogEventsView();
$event_view->setEvents($events);
$event_view->setUser($request->getUser());
$event_view->setCombinedLog(true);
$log_panel = new AphrontPanelView();

View file

@ -22,7 +22,11 @@ class PhabricatorDaemonConsoleController extends PhabricatorDaemonController {
$logs = id(new PhabricatorDaemonLog())->loadAllWhere(
'1 = 1 ORDER BY id DESC LIMIT 15');
$request = $this->getRequest();
$user = $request->getUser();
$daemon_table = new PhabricatorDaemonLogListView();
$daemon_table->setUser($user);
$daemon_table->setDaemonLogs($logs);
$daemon_panel = new AphrontPanelView();

View file

@ -33,6 +33,7 @@ class PhabricatorDaemonLogListController extends PhabricatorDaemonController {
$pager->setURI($request->getRequestURI(), 'page');
$daemon_table = new PhabricatorDaemonLogListView();
$daemon_table->setUser($request->getUser());
$daemon_table->setDaemonLogs($logs);
$daemon_panel = new AphrontPanelView();

View file

@ -59,7 +59,8 @@ class PhabricatorDaemonLogViewController extends PhabricatorDaemonController {
->appendChild(
id(new AphrontFormStaticControl())
->setLabel('Started')
->setValue(date('F jS, Y g:i:s A', $log->getDateCreated())))
->setValue(
phabricator_datetime($log->getDateCreated(), $user)))
->appendChild(
id(new AphrontFormTextAreaControl())
->setLabel('Argv')
@ -73,6 +74,7 @@ class PhabricatorDaemonLogViewController extends PhabricatorDaemonController {
$content[] = $panel;
$event_view = new PhabricatorDaemonLogEventsView();
$event_view->setUser($user);
$event_view->setEvents($events);
$log_panel = new AphrontPanelView();

View file

@ -15,6 +15,7 @@ phutil_require_module('phabricator', 'view/form/base');
phutil_require_module('phabricator', 'view/form/control/static');
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

@ -20,6 +20,7 @@ final class PhabricatorDaemonLogEventsView extends AphrontView {
private $events;
private $combinedLog;
private $user;
public function setEvents(array $events) {
$this->events = $events;
@ -29,14 +30,23 @@ final class PhabricatorDaemonLogEventsView extends AphrontView {
$this->combinedLog = $is_combined;
}
public function setUser(PhabricatorUser $user) {
$this->user = $user;
return $this;
}
public function render() {
$rows = array();
if (!$this->user) {
throw new Exception("Call setUser() before rendering!");
}
foreach ($this->events as $event) {
$row = array(
phutil_escape_html($event->getLogType()),
date('M j, Y', $event->getEpoch()),
date('g:i:s A', $event->getEpoch()),
phabricator_date($event->getEpoch(), $this->user),
phabricator_time($event->getEpoch(), $this->user),
str_replace("\n", '<br />', phutil_escape_html($event->getMessage())),
);

View file

@ -8,6 +8,7 @@
phutil_require_module('phabricator', 'view/base');
phutil_require_module('phabricator', 'view/control/table');
phutil_require_module('phabricator', 'view/utils');
phutil_require_module('phutil', 'markup');

View file

@ -19,14 +19,24 @@
final class PhabricatorDaemonLogListView extends AphrontView {
private $daemonLogs;
private $user;
public function setDaemonLogs(array $daemon_logs) {
$this->daemonLogs = $daemon_logs;
}
public function setUser(PhabricatorUser $user) {
$this->user = $user;
return $this;
}
public function render() {
$rows = array();
if (!$this->user) {
throw new Exception("Call setUser() before rendering!");
}
foreach ($this->daemonLogs as $log) {
$epoch = $log->getDateCreated();
@ -73,8 +83,8 @@ final class PhabricatorDaemonLogListView extends AphrontView {
phutil_escape_html($log->getDaemon()),
phutil_escape_html($log->getHost()),
$log->getPID(),
date('M j, Y', $epoch),
date('g:i A', $epoch),
phabricator_date($epoch, $this->user),
phabricator_time($epoch, $this->user),
phutil_render_tag(
'a',
array(

View file

@ -8,6 +8,7 @@
phutil_require_module('phabricator', 'view/base');
phutil_require_module('phabricator', 'view/control/table');
phutil_require_module('phabricator', 'view/utils');
phutil_require_module('phutil', 'markup');

View file

@ -42,6 +42,7 @@ class DifferentialCommentPreviewController extends DifferentialController {
$comment->setAuthorPHID($author_phid);
$view = new DifferentialRevisionCommentView();
$view->setUser($request->getUser());
$view->setComment($comment);
$view->setHandles($handles);
$view->setMarkupEngine($engine);

View file

@ -26,6 +26,7 @@ final class DifferentialRevisionCommentView extends AphrontView {
private $changesets;
private $target;
private $commentNumber;
private $user;
public function setComment($comment) {
$this->comment = $comment;
@ -67,8 +68,17 @@ final class DifferentialRevisionCommentView extends AphrontView {
return $this;
}
public function setUser(PhabricatorUser $user) {
$this->user = $user;
return $this;
}
public function render() {
if (!$this->user) {
throw new Exception("Call setUser() before rendering!");
}
require_celerity_resource('phabricator-remarkup-css');
require_celerity_resource('differential-revision-comment-css');
@ -81,7 +91,7 @@ final class DifferentialRevisionCommentView extends AphrontView {
if ($this->preview) {
$date = 'COMMENT PREVIEW';
} else {
$date = date('F jS, Y g:i:s A', $comment->getDateCreated());
$date = phabricator_datetime($comment->getDateCreated(), $this->user);
}
$info = array($date);

View file

@ -11,6 +11,7 @@ phutil_require_module('phabricator', 'applications/differential/storage/comment'
phutil_require_module('phabricator', 'infrastructure/celerity/api');
phutil_require_module('phabricator', 'infrastructure/javelin/api');
phutil_require_module('phabricator', 'view/base');
phutil_require_module('phabricator', 'view/utils');
phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'utils');

View file

@ -68,6 +68,7 @@ final class DifferentialRevisionCommentListView extends AphrontView {
foreach ($this->comments as $comment) {
$view = new DifferentialRevisionCommentView();
$view->setComment($comment);
$view->setUser($this->user);
$view->setHandles($this->handles);
$view->setMarkupEngine($engine);
$view->setInlineComments(idx($inlines, $comment->getID(), array()));

View file

@ -28,6 +28,9 @@ class PhabricatorFileViewController extends PhabricatorFileController {
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$file = id(new PhabricatorFile())->loadOneWhere(
'phid = %s',
$this->phid);
@ -93,7 +96,7 @@ class PhabricatorFileViewController extends PhabricatorFileController {
id(new AphrontFormStaticControl())
->setLabel('Created')
->setName('created')
->setValue(date('Y-m-d g:i:s A', $file->getDateCreated())))
->setValue(phabricator_datetime($file->getDateCreated(), $user)))
->appendChild(
id(new AphrontFormStaticControl())
->setLabel('Mime Type')

View file

@ -18,6 +18,7 @@ phutil_require_module('phabricator', 'view/form/base');
phutil_require_module('phabricator', 'view/form/control/static');
phutil_require_module('phabricator', 'view/form/control/submit');
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

@ -50,6 +50,7 @@ class ManiphestTaskDescriptionChangeController extends ManiphestController {
$view = new ManiphestTransactionDetailView();
$view->setTransactionGroup($transactions);
$view->setHandles($handles);
$view->setUser($user);
$view->setMarkupEngine($engine);
$view->setRenderSummaryOnly(true);
$view->setRenderFullSummary(true);

View file

@ -160,6 +160,7 @@ class ManiphestTaskListController extends ManiphestController {
} else {
foreach ($tasks as $group => $list) {
$task_list = new ManiphestTaskListView();
$task_list->setUser($user);
$task_list->setTasks($list);
$task_list->setHandles($handles);

View file

@ -20,6 +20,7 @@ class ManiphestTaskListView extends AphrontView {
private $tasks;
private $handles;
private $user;
public function setTasks(array $tasks) {
$this->tasks = $tasks;
@ -31,12 +32,18 @@ class ManiphestTaskListView extends AphrontView {
return $this;
}
public function setUser(PhabricatorUser $user) {
$this->user = $user;
return $this;
}
public function render() {
$views = array();
foreach ($this->tasks as $task) {
$view = new ManiphestTaskSummaryView();
$view->setTask($task);
$view->setUser($this->user);
$view->setHandles($this->handles);
$views[] = $view->render();
}

View file

@ -20,6 +20,7 @@ class ManiphestTaskSummaryView extends AphrontView {
private $task;
private $handles;
private $user;
public function setTask(ManiphestTask $task) {
$this->task = $task;
@ -31,7 +32,17 @@ class ManiphestTaskSummaryView extends AphrontView {
return $this;
}
public function setUser(PhabricatorUser $user) {
$this->user = $user;
return $this;
}
public function render() {
if (!$this->user) {
throw new Exception("Call setUser() before rendering!");
}
$task = $this->task;
$handles = $this->handles;
@ -76,7 +87,7 @@ class ManiphestTaskSummaryView extends AphrontView {
ManiphestTaskPriority::getTaskPriorityName($task->getPriority()).
'</td>'.
'<td class="maniphest-task-updated">'.
phabricator_format_timestamp($task->getDateModified()).
phabricator_datetime($task->getDateModified(), $this->user).
'</td>'.
'</tr>'.
'</table>';

View file

@ -27,6 +27,7 @@ class ManiphestTransactionDetailView extends AphrontView {
private $renderSummaryOnly;
private $renderFullSummary;
private $user;
public function setTransactionGroup(array $transactions) {
$this->transactions = $transactions;
@ -71,6 +72,11 @@ class ManiphestTransactionDetailView extends AphrontView {
return $this;
}
public function setUser(PhabricatorUser $user) {
$this->user = $user;
return $this;
}
public function renderForEmail($with_date) {
$this->forEmail = true;
@ -87,8 +93,11 @@ class ManiphestTransactionDetailView extends AphrontView {
}
$desc = $author.' '.$desc.'.';
if ($with_date) {
$desc = 'On '.date('M jS \a\t g:i A', $transaction->getDateCreated()).
', '.$desc;
// NOTE: This is going into a (potentially multi-recipient) email so
// we can't use a single user's timezone preferences. Use the server's
// instead, but make the timezone explicit.
$datetime = date('M jS \a\t g:i A T', $transaction->getDateCreated());
$desc = "On {$datetime}, {$desc}";
}
$descs[] = $desc;
if ($transaction->hasComments()) {
@ -114,6 +123,11 @@ class ManiphestTransactionDetailView extends AphrontView {
}
public function render() {
if (!$this->user) {
throw new Exception("Call setUser() before render()!");
}
$handles = $this->handles;
$transactions = $this->transactions;
@ -177,7 +191,9 @@ class ManiphestTransactionDetailView extends AphrontView {
if ($this->preview) {
$timestamp = 'COMMENT PREVIEW';
} else {
$timestamp = phabricator_format_timestamp($transaction->getDateCreated());
$timestamp = phabricator_datetime(
$transaction->getDateCreated(),
$this->user);
}
$info = array();

View file

@ -80,6 +80,7 @@ class ManiphestTransactionListView extends AphrontView {
$sequence = 1;
foreach ($groups as $group) {
$view = new ManiphestTransactionDetailView();
$view->setUser($this->user);
$view->setTransactionGroup($group);
$view->setHandles($this->handles);
$view->setMarkupEngine($this->markupEngine);

View file

@ -21,6 +21,7 @@ class PhabricatorMetaMTAListController extends PhabricatorMetaMTAController {
public function processRequest() {
// Get a page of mails together with pager.
$request = $this->getRequest();
$user = $request->getUser();
$offset = $request->getInt('offset', 0);
$related_phid = $request->getStr('phid');
@ -60,7 +61,7 @@ class PhabricatorMetaMTAListController extends PhabricatorMetaMTAController {
PhabricatorMetaMTAMail::getReadableStatus($mail->getStatus()),
$mail->getRetryCount(),
($mail->getNextRetry() - time()).' s',
date('Y-m-d g:i:s A', $mail->getDateCreated()),
phabricator_datetime($mail->getDateCreated(), $user),
(time() - $mail->getDateModified()).' s',
phutil_escape_html($mail->getSubject()),
phutil_render_tag(

View file

@ -13,6 +13,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');

View file

@ -18,19 +18,22 @@
function phabricator_date($epoch, $user) {
$zone = new DateTimeZone($user->getTimezoneIdentifier());
$date = new DateTime('@'.$epoch, $zone);
$date = new DateTime('@'.$epoch);
$date->setTimeZone($zone);
return $date->format('M j Y');
}
function phabricator_time($epoch, $user) {
$zone = new DateTimeZone($user->getTimezoneIdentifier());
$date = new DateTime('@'.$epoch, $zone);
$date = new DateTime('@'.$epoch);
$date->setTimeZone($zone);
return $date->format('g:i A');
}
function phabricator_datetime($epoch, $user) {
$zone = new DateTimeZone($user->getTimezoneIdentifier());
$date = new DateTime('@'.$epoch, $zone);
$date = new DateTime('@'.$epoch);
$date->setTimeZone($zone);
return $date->format('M j Y, g:i A');
}

View file

@ -49,8 +49,8 @@
.maniphest-task-summary td.maniphest-task-updated {
text-align: left;
width: 11%;
min-width: 120px;
width: 13%;
min-width: 160px;
}
.maniphest-task-summary .pri-bullet {