Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15399226
D8341.id19833.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
12 KB
Referenced Files
None
Subscribers
None
D8341.id19833.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -95,6 +95,8 @@
'BuildStepImplementation' => 'applications/harbormaster/step/BuildStepImplementation.php',
'CalendarColors' => 'applications/calendar/constants/CalendarColors.php',
'CalendarConstants' => 'applications/calendar/constants/CalendarConstants.php',
+ 'CalendarTimeUtil' => 'applications/calendar/util/CalendarTimeUtil.php',
+ 'CalendarTimeUtilTestCase' => 'applications/calendar/__tests__/CalendarTimeUtilTestCase.php',
'CelerityAPI' => 'infrastructure/celerity/CelerityAPI.php',
'CelerityManagementMapWorkflow' => 'infrastructure/celerity/management/CelerityManagementMapWorkflow.php',
'CelerityManagementWorkflow' => 'infrastructure/celerity/management/CelerityManagementWorkflow.php',
@@ -291,8 +293,6 @@
'ConpherenceThreadListView' => 'applications/conpherence/view/ConpherenceThreadListView.php',
'ConpherenceThreadMailReceiver' => 'applications/conpherence/mail/ConpherenceThreadMailReceiver.php',
'ConpherenceThreadQuery' => 'applications/conpherence/query/ConpherenceThreadQuery.php',
- 'ConpherenceTimeUtil' => 'applications/conpherence/util/ConpherenceTimeUtil.php',
- 'ConpherenceTimeUtilTestCase' => 'applications/conpherence/__tests__/ConpherenceTimeUtilTestCase.php',
'ConpherenceTransaction' => 'applications/conpherence/storage/ConpherenceTransaction.php',
'ConpherenceTransactionComment' => 'applications/conpherence/storage/ConpherenceTransactionComment.php',
'ConpherenceTransactionQuery' => 'applications/conpherence/query/ConpherenceTransactionQuery.php',
@@ -2658,6 +2658,7 @@
'AphrontWebpageResponse' => 'AphrontHTMLResponse',
'AuditActionMenuEventListener' => 'PhabricatorEventListener',
'CalendarColors' => 'CalendarConstants',
+ 'CalendarTimeUtilTestCase' => 'PhabricatorTestCase',
'CelerityManagementMapWorkflow' => 'CelerityManagementWorkflow',
'CelerityManagementWorkflow' => 'PhabricatorManagementWorkflow',
'CelerityPhabricatorResourceController' => 'CelerityResourceController',
@@ -2852,7 +2853,6 @@
'ConpherenceThreadListView' => 'AphrontView',
'ConpherenceThreadMailReceiver' => 'PhabricatorObjectMailReceiver',
'ConpherenceThreadQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
- 'ConpherenceTimeUtilTestCase' => 'PhabricatorTestCase',
'ConpherenceTransaction' => 'PhabricatorApplicationTransaction',
'ConpherenceTransactionComment' => 'PhabricatorApplicationTransactionComment',
'ConpherenceTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
diff --git a/src/applications/conpherence/__tests__/ConpherenceTimeUtilTestCase.php b/src/applications/calendar/__tests__/CalendarTimeUtilTestCase.php
rename from src/applications/conpherence/__tests__/ConpherenceTimeUtilTestCase.php
rename to src/applications/calendar/__tests__/CalendarTimeUtilTestCase.php
--- a/src/applications/conpherence/__tests__/ConpherenceTimeUtilTestCase.php
+++ b/src/applications/calendar/__tests__/CalendarTimeUtilTestCase.php
@@ -1,13 +1,13 @@
<?php
-final class ConpherenceTimeUtilTestCase extends PhabricatorTestCase {
+final class CalendarTimeUtilTestCase extends PhabricatorTestCase {
- public function testWidgetTimestampsAtMidnight() {
+ public function testTimestampsAtMidnight() {
$u = new PhabricatorUser();
$u->setTimezoneIdentifier('America/Los_Angeles');
$days = $this->getAllDays();
foreach ($days as $day) {
- $data = ConpherenceTimeUtil::getCalendarWidgetTimestamps(
+ $data = CalendarTimeUtil::getCalendarWidgetTimestamps(
$u,
$day);
@@ -17,14 +17,15 @@
}
}
- public function testWidgetTimestampsStartDay() {
+ public function testTimestampsStartDay() {
$u = new PhabricatorUser();
$u->setTimezoneIdentifier('America/Los_Angeles');
$days = $this->getAllDays();
foreach ($days as $day) {
- $data = ConpherenceTimeUtil::getCalendarWidgetTimestamps(
+ $data = CalendarTimeUtil::getTimestamps(
$u,
- $day);
+ $day,
+ 1);
$this->assertEqual(
$day,
@@ -34,9 +35,10 @@
$t = 1370202281; // 2013-06-02 12:44:41 -0700 -- a Sunday
$time = PhabricatorTime::pushTime($t, 'America/Los_Angeles');
foreach ($days as $day) {
- $data = ConpherenceTimeUtil::getCalendarWidgetTimestamps(
+ $data = CalendarTimeUtil::getTimestamps(
$u,
- $day);
+ $day,
+ 1);
$this->assertEqual(
$day,
diff --git a/src/applications/conpherence/util/ConpherenceTimeUtil.php b/src/applications/calendar/util/CalendarTimeUtil.php
rename from src/applications/conpherence/util/ConpherenceTimeUtil.php
rename to src/applications/calendar/util/CalendarTimeUtil.php
--- a/src/applications/conpherence/util/ConpherenceTimeUtil.php
+++ b/src/applications/calendar/util/CalendarTimeUtil.php
@@ -1,37 +1,62 @@
<?php
-
-final class ConpherenceTimeUtil {
+/**
+ * This class is useful for generating various time objects, relative to the
+ * user and their timezone.
+ *
+ * For now, the class exposes two sets of static methods for the two main
+ * calendar views - one for the conpherence calendar widget and one for the
+ * user profile calendar view. These have slight differences such as
+ * conpherence showing both a three day "today 'til 2 days from now" *and*
+ * a Sunday -> Saturday list, whilest the profile view shows a more simple
+ * seven day rolling list of events.
+ */
+final class CalendarTimeUtil {
public static function getCalendarEventEpochs(
PhabricatorUser $user,
- $start_day_str = 'Sunday') {
+ $start_day_str = 'Sunday',
+ $days = 9) {
$objects = self::getStartDateTimeObjects($user, $start_day_str);
$start_day = $objects['start_day'];
$end_day = clone $start_day;
- $end_day->modify('+9 days');
+ $end_day->modify('+'.$days.' days');
return array(
'start_epoch' => $start_day->format('U'),
'end_epoch' => $end_day->format('U'));
}
+ public static function getCalendarWeekTimestamps(
+ PhabricatorUser $user) {
+ return self::getTimestamps($user, 'Today', 7);
+ }
+
public static function getCalendarWidgetTimestamps(
+ PhabricatorUser $user) {
+ return self::getTimestamps($user, 'Sunday', 9);
+ }
+
+ /**
+ * Public for testing purposes only. You should probably use one of the
+ * functions above.
+ */
+ public static function getTimestamps(
PhabricatorUser $user,
- $start_day_str = 'Sunday') {
+ $start_day_str,
+ $days) {
$objects = self::getStartDateTimeObjects($user, $start_day_str);
$start_day = $objects['start_day'];
$timestamps = array();
- for ($day = 0; $day < 9; $day++) {
+ for ($day = 0; $day < $days; $day++) {
$timestamp = clone $start_day;
$timestamp->modify(sprintf('+%d days', $day));
$timestamps[] = $timestamp;
}
return array(
'today' => $objects['today'],
- 'epoch_stamps' => $timestamps
- );
+ 'epoch_stamps' => $timestamps);
}
private static function getStartDateTimeObjects(
@@ -43,7 +68,8 @@
$today = new DateTime('@'.$today_epoch);
$today->setTimeZone($timezone);
- if ($today->format('l') == $start_day_str) {
+ if (strtolower($start_day_str) == 'today' ||
+ $today->format('l') == $start_day_str) {
$start_day = clone $today;
} else {
$start_epoch = PhabricatorTime::parseLocalTime(
diff --git a/src/applications/conpherence/controller/ConpherenceWidgetController.php b/src/applications/conpherence/controller/ConpherenceWidgetController.php
--- a/src/applications/conpherence/controller/ConpherenceWidgetController.php
+++ b/src/applications/conpherence/controller/ConpherenceWidgetController.php
@@ -200,7 +200,7 @@
$content = array();
$layout = id(new AphrontMultiColumnView())
->setFluidLayout(true);
- $timestamps = ConpherenceTimeUtil::getCalendarWidgetTimestamps($user);
+ $timestamps = CalendarTimeUtil::getCalendarWidgetTimestamps($user);
$today = $timestamps['today'];
$epoch_stamps = $timestamps['epoch_stamps'];
$one_day = 24 * 60 * 60;
diff --git a/src/applications/conpherence/query/ConpherenceThreadQuery.php b/src/applications/conpherence/query/ConpherenceThreadQuery.php
--- a/src/applications/conpherence/query/ConpherenceThreadQuery.php
+++ b/src/applications/conpherence/query/ConpherenceThreadQuery.php
@@ -217,7 +217,7 @@
$participant_phids = array_mergev($participant_phids);
$file_phids = array_mergev($file_phids);
- $epochs = ConpherenceTimeUtil::getCalendarEventEpochs(
+ $epochs = CalendarTimeUtil::getCalendarEventEpochs(
$this->getViewer());
$start_epoch = $epochs['start_epoch'];
$end_epoch = $epochs['end_epoch'];
diff --git a/src/applications/people/controller/PhabricatorPeopleProfileController.php b/src/applications/people/controller/PhabricatorPeopleProfileController.php
--- a/src/applications/people/controller/PhabricatorPeopleProfileController.php
+++ b/src/applications/people/controller/PhabricatorPeopleProfileController.php
@@ -141,51 +141,71 @@
}
private function renderUserCalendar(PhabricatorUser $user) {
- $now = time();
- $year = phabricator_format_local_time($now, $user, 'Y');
- $month = phabricator_format_local_time($now, $user, 'm');
- $day = phabricator_format_local_time($now, $user, 'j');
+ $viewer = $this->getRequest()->getUser();
+ $epochs = CalendarTimeUtil::getCalendarEventEpochs(
+ $viewer,
+ 'today',
+ 7);
+ $start_epoch = $epochs['start_epoch'];
+ $end_epoch = $epochs['end_epoch'];
$statuses = id(new PhabricatorCalendarEventQuery())
- ->setViewer($user)
+ ->setViewer($viewer)
->withInvitedPHIDs(array($user->getPHID()))
- ->withDateRange(
- strtotime("{$year}-{$month}-{$day}"),
- strtotime("{$year}-{$month}-{$day} +7 days"))
+ ->withDateRange($start_epoch, $end_epoch)
->execute();
+ $timestamps = CalendarTimeUtil::getCalendarWeekTimestamps(
+ $viewer);
+ $today = $timestamps['today'];
+ $epoch_stamps = $timestamps['epoch_stamps'];
$events = array();
- foreach ($statuses as $status) {
- $event = new AphrontCalendarEventView();
- $event->setEpochRange($status->getDateFrom(), $status->getDateTo());
-
- $status_text = $status->getHumanStatus();
- $event->setUserPHID($status->getUserPHID());
- $event->setName($status_text);
- $event->setDescription($status->getDescription());
- $event->setEventID($status->getID());
- $key = date('Y-m-d', $event->getEpochStart());
- $events[$key][] = $event;
- // Populate multiday events
- // Better means?
- $next_day = strtotime("{$key} +1 day");
- if ($event->getEpochEnd() >= $next_day) {
- $nextkey = date('Y-m-d', $next_day);
- $events[$nextkey][] = $event;
+
+ foreach ($epoch_stamps as $day) {
+ $epoch_start = $day->format('U');
+ $next_day = clone $day;
+ $next_day->modify('+1 day');
+ $epoch_end = $next_day->format('U');
+
+ foreach ($statuses as $status) {
+ if ($status->getDateFrom() >= $epoch_end) {
+ // This list is sorted, so we can stop looking.
+ break;
+ }
+
+ $event = new AphrontCalendarEventView();
+ $event->setEpochRange($status->getDateFrom(), $status->getDateTo());
+
+ $status_text = $status->getHumanStatus();
+ $event->setUserPHID($status->getUserPHID());
+ $event->setName($status_text);
+ $event->setDescription($status->getDescription());
+ $event->setEventID($status->getID());
+ $key = date('Y-m-d', $event->getEpochStart());
+ $events[$epoch_start][] = $event;
+ // check if this is a multi day event...!
+ $day_iterator = clone $day;
+ while (true) {
+ $day_iterator->modify('+ 1 day');
+ $day_iterator_end = $day_iterator->format('U');
+ if ($event->getEpochEnd() > $day_iterator_end) {
+ $events[$day_iterator_end][] = $event;
+ } else {
+ break;
+ }
+ }
}
}
- $i = 0;
$week = array();
- for ($i = 0;$i <= 6;$i++) {
- $datetime = strtotime("{$year}-{$month}-{$day} +{$i} days");
- $headertext = phabricator_format_local_time($datetime, $user, 'l, M d');
- $this_day = date('Y-m-d', $datetime);
+ foreach ($epoch_stamps as $day) {
+ $epoch = $day->format('U');
+ $headertext = phabricator_format_local_time($epoch, $user, 'l, M d');
$list = new PHUICalendarListView();
- $list->setUser($user);
+ $list->setUser($viewer);
$list->showBlankState(true);
- if (isset($events[$this_day])) {
- foreach ($events[$this_day] as $event) {
+ if (isset($events[$epoch])) {
+ foreach ($events[$epoch] as $event) {
$list->addEvent($event);
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Mar 18, 3:26 AM (1 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7709313
Default Alt Text
D8341.id19833.diff (12 KB)
Attached To
Mode
D8341: Fix calendar display on profile.
Attached
Detach File
Event Timeline
Log In to Comment