From f07d0ae7c3aee1ca21567f95360acda205950edc Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 18 Mar 2016 08:59:21 -0700 Subject: [PATCH] Make dates/times more concise in Diffusion Summary: I think I like this better -- but maybe right-aligned? Test Plan: {F1180295} {F1180296} Reviewers: chad Reviewed By: chad Differential Revision: https://secure.phabricator.com/D15495 --- .../DiffusionLastModifiedController.php | 2 +- .../view/DiffusionBranchTableView.php | 4 +-- .../view/DiffusionBrowseTableView.php | 2 +- .../view/DiffusionHistoryTableView.php | 4 +-- .../view/DiffusionPushLogListView.php | 4 +-- .../diffusion/view/DiffusionTagListView.php | 4 ++- .../people/storage/PhabricatorUser.php | 32 +++++++++++++++++++ 7 files changed, 43 insertions(+), 9 deletions(-) diff --git a/src/applications/diffusion/controller/DiffusionLastModifiedController.php b/src/applications/diffusion/controller/DiffusionLastModifiedController.php index 0fea238249..8a4debfcea 100644 --- a/src/applications/diffusion/controller/DiffusionLastModifiedController.php +++ b/src/applications/diffusion/controller/DiffusionLastModifiedController.php @@ -103,7 +103,7 @@ final class DiffusionLastModifiedController extends DiffusionController { $modified = DiffusionView::linkCommit( $drequest->getRepository(), $commit->getCommitIdentifier()); - $date = phabricator_datetime($epoch, $viewer); + $date = $viewer->formatShortDateTime($epoch); } else { $modified = ''; $date = ''; diff --git a/src/applications/diffusion/view/DiffusionBranchTableView.php b/src/applications/diffusion/view/DiffusionBranchTableView.php index 462f296bcb..b75228a0ce 100644 --- a/src/applications/diffusion/view/DiffusionBranchTableView.php +++ b/src/applications/diffusion/view/DiffusionBranchTableView.php @@ -39,7 +39,7 @@ final class DiffusionBranchTableView extends DiffusionView { $commit = idx($commits, $branch->getCommitIdentifier()); if ($commit) { $details = $commit->getSummary(); - $datetime = phabricator_datetime($commit->getEpoch(), $viewer); + $datetime = $viewer->formatShortDateTime($commit->getEpoch()); $buildable = idx($buildables, $commit->getPHID()); if ($buildable) { $build_status = $this->renderBuildable($buildable); @@ -147,7 +147,7 @@ final class DiffusionBranchTableView extends DiffusionView { '', 'wide', '', - '', + 'right', )); $view->setColumnVisibility( array( diff --git a/src/applications/diffusion/view/DiffusionBrowseTableView.php b/src/applications/diffusion/view/DiffusionBrowseTableView.php index fa5342ad9d..ffc5ce61ed 100644 --- a/src/applications/diffusion/view/DiffusionBrowseTableView.php +++ b/src/applications/diffusion/view/DiffusionBrowseTableView.php @@ -129,7 +129,7 @@ final class DiffusionBrowseTableView extends DiffusionView { '', '', 'wide', - '', + 'right', )); $view->setColumnVisibility( array( diff --git a/src/applications/diffusion/view/DiffusionHistoryTableView.php b/src/applications/diffusion/view/DiffusionHistoryTableView.php index e62c4382c9..a9fb34e683 100644 --- a/src/applications/diffusion/view/DiffusionHistoryTableView.php +++ b/src/applications/diffusion/view/DiffusionHistoryTableView.php @@ -95,7 +95,7 @@ final class DiffusionHistoryTableView extends DiffusionView { $epoch = $history->getEpoch(); if ($epoch) { - $committed = phabricator_datetime($epoch, $viewer); + $committed = $viewer->formatShortDateTime($epoch); } else { $committed = null; } @@ -195,7 +195,7 @@ final class DiffusionHistoryTableView extends DiffusionView { '', '', 'wide', - '', + 'right', )); $view->setColumnVisibility( array( diff --git a/src/applications/diffusion/view/DiffusionPushLogListView.php b/src/applications/diffusion/view/DiffusionPushLogListView.php index 7cc02a49b4..73a44794e8 100644 --- a/src/applications/diffusion/view/DiffusionPushLogListView.php +++ b/src/applications/diffusion/view/DiffusionPushLogListView.php @@ -88,7 +88,7 @@ final class DiffusionPushLogListView extends AphrontView { // TODO: Make these human-readable. $log->getChangeFlags(), $log->getPushEvent()->getRejectCode(), - phabricator_datetime($log->getEpoch(), $viewer), + $viewer->formatShortDateTime($log->getEpoch()), ); } @@ -119,7 +119,7 @@ final class DiffusionPushLogListView extends AphrontView { 'wide', 'n', 'n', - 'date', + 'right', )); return $table; diff --git a/src/applications/diffusion/view/DiffusionTagListView.php b/src/applications/diffusion/view/DiffusionTagListView.php index 923fa30fc5..df59925522 100644 --- a/src/applications/diffusion/view/DiffusionTagListView.php +++ b/src/applications/diffusion/view/DiffusionTagListView.php @@ -28,6 +28,7 @@ final class DiffusionTagListView extends DiffusionView { public function render() { $drequest = $this->getDiffusionRequest(); $repository = $drequest->getRepository(); + $viewer = $this->getViewer(); $buildables = $this->loadBuildables($this->commits); $has_builds = false; @@ -100,7 +101,7 @@ final class DiffusionTagListView extends DiffusionView { $build, $author, $description, - phabricator_datetime($tag->getEpoch(), $this->getViewer()), + $viewer->formatShortDateTime($tag->getEpoch()), ); } @@ -123,6 +124,7 @@ final class DiffusionTagListView extends DiffusionView { '', '', 'wide', + 'right', )) ->setColumnVisibility( array( diff --git a/src/applications/people/storage/PhabricatorUser.php b/src/applications/people/storage/PhabricatorUser.php index 07c5695945..ed6fceba1e 100644 --- a/src/applications/people/storage/PhabricatorUser.php +++ b/src/applications/people/storage/PhabricatorUser.php @@ -742,6 +742,38 @@ final class PhabricatorUser return new DateTimeZone($this->getTimezoneIdentifier()); } + public function formatShortDateTime($when, $now = null) { + if ($now === null) { + $now = PhabricatorTime::getNow(); + } + + try { + $when = new DateTime('@'.$when); + $now = new DateTime('@'.$now); + } catch (Exception $ex) { + return null; + } + + $zone = $this->getTimeZone(); + + $when->setTimeZone($zone); + $now->setTimeZone($zone); + + if ($when->format('Y') !== $now->format('Y')) { + // Different year, so show "Feb 31 2075". + $format = 'M j Y'; + } else if ($when->format('Ymd') !== $now->format('Ymd')) { + // Same year but different month and day, so show "Feb 31". + $format = 'M j'; + } else { + // Same year, month and day so show a time of day. + $pref_time = PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT; + $format = $this->getPreference($pref_time); + } + + return $when->format($format); + } + public function getPreference($key) { $preferences = $this->loadPreferences();