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

Remove "viewerDateFrom" / "viewerDateTo" in favor of CalendarDateTime methods

Summary: Ref T10747. The CalendarDateTime object now carries the viewer timezone as part of its state, so we don't need to have separate accessors.

Test Plan:
  - Viewed events, checked that crumbs render properly.
  - Edited events.
  - Created new events.
  - Viewed calendar.
  - Viewed event detail pages.
  - Viewed profile mini-calendar.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10747

Differential Revision: https://secure.phabricator.com/D16662
This commit is contained in:
epriestley 2016-10-04 09:47:38 -07:00
parent e042533375
commit 37f35e9ecc
7 changed files with 79 additions and 104 deletions

View file

@ -27,8 +27,8 @@ final class PhabricatorCalendarEventViewController
$page_title = $monogram.' '.$event->getName();
$crumbs = $this->buildApplicationCrumbs();
$start = new DateTime('@'.$event->getViewerDateFrom());
$start->setTimeZone($viewer->getTimeZone());
$start = $event->newStartDateTime()
->newPHPDateTime();
$crumbs->addTextCrumb(
$start->format('F Y'),

View file

@ -155,6 +155,13 @@ final class PhabricatorCalendarEventEditEngine
}
if ($this->getIsCreate() || $object->getIsRecurring()) {
$until_datetime = $object->newUntilDateTime();
if ($until_datetime) {
$until_epoch = $until_datetime->getEpoch();
} else {
$until_epoch = null;
}
$fields[] = id(new PhabricatorEpochEditField())
->setAllowNull(true)
->setKey('until')
@ -164,50 +171,50 @@ final class PhabricatorCalendarEventEditEngine
->setDescription(pht('Last instance of the event.'))
->setConduitDescription(pht('Change when the event repeats until.'))
->setConduitTypeDescription(pht('New final event time.'))
->setValue($object->getRecurrenceEndDate());
->setValue($until_epoch);
}
$fields[] = id(new PhabricatorBoolEditField())
->setKey('isAllDay')
->setLabel(pht('All Day'))
->setOptions(pht('Normal Event'), pht('All Day Event'))
->setTransactionType(
PhabricatorCalendarEventAllDayTransaction::TRANSACTIONTYPE)
->setDescription(pht('Marks this as an all day event.'))
->setConduitDescription(pht('Make the event an all day event.'))
->setConduitTypeDescription(pht('Mark the event as an all day event.'))
->setValue($object->getIsAllDay());
->setKey('isAllDay')
->setLabel(pht('All Day'))
->setOptions(pht('Normal Event'), pht('All Day Event'))
->setTransactionType(
PhabricatorCalendarEventAllDayTransaction::TRANSACTIONTYPE)
->setDescription(pht('Marks this as an all day event.'))
->setConduitDescription(pht('Make the event an all day event.'))
->setConduitTypeDescription(pht('Mark the event as an all day event.'))
->setValue($object->getIsAllDay());
$fields[] = id(new PhabricatorEpochEditField())
->setKey('start')
->setLabel(pht('Start'))
->setTransactionType(
PhabricatorCalendarEventStartDateTransaction::TRANSACTIONTYPE)
->setDescription(pht('Start time of the event.'))
->setConduitDescription(pht('Change the start time of the event.'))
->setConduitTypeDescription(pht('New event start time.'))
->setValue($object->getViewerDateFrom());
->setKey('start')
->setLabel(pht('Start'))
->setTransactionType(
PhabricatorCalendarEventStartDateTransaction::TRANSACTIONTYPE)
->setDescription(pht('Start time of the event.'))
->setConduitDescription(pht('Change the start time of the event.'))
->setConduitTypeDescription(pht('New event start time.'))
->setValue($object->getStartDateTimeEpoch());
$fields[] = id(new PhabricatorEpochEditField())
->setKey('end')
->setLabel(pht('End'))
->setTransactionType(
PhabricatorCalendarEventEndDateTransaction::TRANSACTIONTYPE)
->setDescription(pht('End time of the event.'))
->setConduitDescription(pht('Change the end time of the event.'))
->setConduitTypeDescription(pht('New event end time.'))
->setValue($object->getViewerDateTo());
->setKey('end')
->setLabel(pht('End'))
->setTransactionType(
PhabricatorCalendarEventEndDateTransaction::TRANSACTIONTYPE)
->setDescription(pht('End time of the event.'))
->setConduitDescription(pht('Change the end time of the event.'))
->setConduitTypeDescription(pht('New event end time.'))
->setValue($object->getEndDateTimeEpoch());
$fields[] = id(new PhabricatorIconSetEditField())
->setKey('icon')
->setLabel(pht('Icon'))
->setIconSet(new PhabricatorCalendarIconSet())
->setTransactionType(
PhabricatorCalendarEventIconTransaction::TRANSACTIONTYPE)
->setDescription(pht('Event icon.'))
->setConduitDescription(pht('Change the event icon.'))
->setConduitTypeDescription(pht('New event icon.'))
->setValue($object->getIcon());
->setKey('icon')
->setLabel(pht('Icon'))
->setIconSet(new PhabricatorCalendarIconSet())
->setTransactionType(
PhabricatorCalendarEventIconTransaction::TRANSACTIONTYPE)
->setDescription(pht('Event icon.'))
->setConduitDescription(pht('Change the event icon.'))
->setConduitTypeDescription(pht('New event icon.'))
->setValue($object->getIcon());
return $fields;
}

View file

@ -99,7 +99,7 @@ final class PhabricatorCalendarEventQuery
protected function getPagingValueMap($cursor, array $keys) {
$event = $this->loadCursorObject($cursor);
return array(
'start' => $event->getViewerDateFrom(),
'start' => $event->getStartDateTimeEpoch(),
'id' => $event->getID(),
);
}
@ -177,9 +177,9 @@ final class PhabricatorCalendarEventQuery
$modify_key = '+1 '.$frequency;
if (($this->rangeBegin !== null) &&
($this->rangeBegin > $event->getViewerDateFrom())) {
($this->rangeBegin > $event->getStartDateTimeEpoch())) {
$max_date = $this->rangeBegin - $duration;
$date = $event->getViewerDateFrom();
$date = $event->getStartDateTimeEpoch();
$datetime = PhabricatorTime::getDateTimeFromEpoch($date, $viewer);
while ($date < $max_date) {
@ -191,7 +191,7 @@ final class PhabricatorCalendarEventQuery
$start = $this->rangeBegin;
} else {
$start = $event->getViewerDateFrom() - $duration;
$start = $event->getStartDateTimeEpoch() - $duration;
}
$date = $start;
@ -238,9 +238,9 @@ final class PhabricatorCalendarEventQuery
if ($raw_limit) {
if (count($events) > $raw_limit) {
$events = msort($events, 'getViewerDateFrom');
$events = msort($events, 'getStartDateTimeEpoch');
$events = array_slice($events, 0, $raw_limit, true);
$enforced_end = last($events)->getViewerDateFrom();
$enforced_end = last($events)->getStartDateTimeEpoch();
}
}
}
@ -308,7 +308,7 @@ final class PhabricatorCalendarEventQuery
}
}
$events = msort($events, 'getViewerDateFrom');
$events = msort($events, 'getStartDateTimeEpoch');
return $events;
}
@ -500,7 +500,7 @@ final class PhabricatorCalendarEventQuery
}
}
$events = msort($events, 'getViewerDateFrom');
$events = msort($events, 'getStartDateTimeEpoch');
return $events;
}
@ -510,8 +510,8 @@ final class PhabricatorCalendarEventQuery
$range_end = $this->rangeEnd;
foreach ($events as $key => $event) {
$event_start = $event->getViewerDateFrom();
$event_end = $event->getViewerDateTo();
$event_start = $event->getStartDateTimeEpoch();
$event_end = $event->getEndDateTimeEpoch();
if ($range_start && $event_end < $range_start) {
unset($events[$key]);

View file

@ -343,8 +343,8 @@ final class PhabricatorCalendarEventSearchEngine
$month_view->setUser($viewer);
foreach ($events as $event) {
$epoch_min = $event->getViewerDateFrom();
$epoch_max = $event->getViewerDateTo();
$epoch_min = $event->getStartDateTimeEpoch();
$epoch_max = $event->getEndDateTimeEpoch();
$event_view = id(new AphrontCalendarEventView())
->setHostPHID($event->getHostPHID())
@ -408,8 +408,8 @@ final class PhabricatorCalendarEventSearchEngine
$event,
PhabricatorPolicyCapability::CAN_EDIT);
$epoch_min = $event->getViewerDateFrom();
$epoch_max = $event->getViewerDateTo();
$epoch_min = $event->getStartDateTimeEpoch();
$epoch_max = $event->getEndDateTimeEpoch();
$status_icon = $event->getDisplayIcon($viewer);
$status_color = $event->getDisplayIconColor($viewer);

View file

@ -49,8 +49,6 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
private $parentEvent = self::ATTACHABLE;
private $invitees = self::ATTACHABLE;
private $viewerDateFrom;
private $viewerDateTo;
private $viewerTimezone;
// Frequency Constants
@ -273,46 +271,8 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
return $ghost;
}
public function getViewerDateFrom() {
if ($this->viewerDateFrom === null) {
throw new PhutilInvalidStateException('applyViewerTimezone');
}
return $this->viewerDateFrom;
}
public function getViewerDateTo() {
if ($this->viewerDateTo === null) {
throw new PhutilInvalidStateException('applyViewerTimezone');
}
return $this->viewerDateTo;
}
public function applyViewerTimezone(PhabricatorUser $viewer) {
if (!$this->getIsAllDay()) {
$this->viewerDateFrom = $this->getDateFrom();
$this->viewerDateTo = $this->getDateTo();
} else {
$zone = $viewer->getTimeZone();
$this->viewerDateFrom = $this->getDateEpochForTimezone(
$this->getAllDayDateFrom(),
new DateTimeZone('UTC'),
'Y-m-d',
null,
$zone);
$this->viewerDateTo = $this->getDateEpochForTimezone(
$this->getAllDayDateTo(),
new DateTimeZone('UTC'),
'Y-m-d 23:59:00',
null,
$zone);
}
$this->viewerTimezone = $viewer->getTimezoneIdentifier();
return $this;
}
@ -407,7 +367,9 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
* @return int Event start date for availability caches.
*/
public function getDateFromForCache() {
return ($this->getViewerDateFrom() - phutil_units('15 minutes in seconds'));
$epoch = $this->getStartDateTimeEpoch();
$window = phutil_units('15 minutes in seconds');
return ($epoch - $window);
}
protected function getConfiguration() {
@ -593,14 +555,12 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
PhabricatorUser $viewer,
$show_end) {
if ($show_end) {
$min_date = PhabricatorTime::getDateTimeFromEpoch(
$this->getViewerDateFrom(),
$viewer);
$start = $this->newStartDateTime();
$end = $this->newEndDateTime();
$max_date = PhabricatorTime::getDateTimeFromEpoch(
$this->getViewerDateTo(),
$viewer);
if ($show_end) {
$min_date = $start->newPHPDateTime();
$max_date = $end->newPHPDateTime();
$min_day = $min_date->format('Y m d');
$max_day = $max_date->format('Y m d');
@ -610,8 +570,8 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
$show_end_date = false;
}
$min_epoch = $this->getViewerDateFrom();
$max_epoch = $this->getViewerDateTo();
$min_epoch = $start->getEpoch();
$max_epoch = $end->getEpoch();
if ($this->getIsAllDay()) {
if ($show_end_date) {
@ -803,6 +763,10 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
return $this->newDateTimeFromEpoch($epoch);
}
public function getStartDateTimeEpoch() {
return $this->newStartDateTime()->getEpoch();
}
public function newEndDateTime() {
$datetime = $this->getParameter('endDateTime');
if ($datetime) {
@ -813,6 +777,10 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
return $this->newDateTimeFromEpoch($epoch);
}
public function getEndDateTimeEpoch() {
return $this->newEndDateTime()->getEpoch();
}
public function newUntilDateTime() {
$datetime = $this->getParameter('untilDateTime');
if ($datetime) {

View file

@ -205,8 +205,8 @@ final class PhabricatorPeopleProfileViewController
$event,
PhabricatorPolicyCapability::CAN_EDIT);
$epoch_min = $event->getViewerDateFrom();
$epoch_max = $event->getViewerDateTo();
$epoch_min = $event->getStartDateTimeEpoch();
$epoch_max = $event->getEndDateTimeEpoch();
$event_view = id(new AphrontCalendarEventView())
->setCanEdit($can_edit)

View file

@ -432,7 +432,7 @@ final class PhabricatorPeopleQuery
while (true) {
foreach ($events as $event) {
$from = $event->getDateFromForCache();
$to = $event->getViewerDateTo();
$to = $event->getEndDateTimeEpoch();
if (($from <= $cursor) && ($to > $cursor)) {
$cursor = $to;
continue 2;