1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-27 09:12: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(); $page_title = $monogram.' '.$event->getName();
$crumbs = $this->buildApplicationCrumbs(); $crumbs = $this->buildApplicationCrumbs();
$start = new DateTime('@'.$event->getViewerDateFrom()); $start = $event->newStartDateTime()
$start->setTimeZone($viewer->getTimeZone()); ->newPHPDateTime();
$crumbs->addTextCrumb( $crumbs->addTextCrumb(
$start->format('F Y'), $start->format('F Y'),

View file

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

View file

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

View file

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

View file

@ -49,8 +49,6 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
private $parentEvent = self::ATTACHABLE; private $parentEvent = self::ATTACHABLE;
private $invitees = self::ATTACHABLE; private $invitees = self::ATTACHABLE;
private $viewerDateFrom;
private $viewerDateTo;
private $viewerTimezone; private $viewerTimezone;
// Frequency Constants // Frequency Constants
@ -273,46 +271,8 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
return $ghost; 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) { 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(); $this->viewerTimezone = $viewer->getTimezoneIdentifier();
return $this; return $this;
} }
@ -407,7 +367,9 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
* @return int Event start date for availability caches. * @return int Event start date for availability caches.
*/ */
public function getDateFromForCache() { 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() { protected function getConfiguration() {
@ -593,14 +555,12 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
PhabricatorUser $viewer, PhabricatorUser $viewer,
$show_end) { $show_end) {
if ($show_end) { $start = $this->newStartDateTime();
$min_date = PhabricatorTime::getDateTimeFromEpoch( $end = $this->newEndDateTime();
$this->getViewerDateFrom(),
$viewer);
$max_date = PhabricatorTime::getDateTimeFromEpoch( if ($show_end) {
$this->getViewerDateTo(), $min_date = $start->newPHPDateTime();
$viewer); $max_date = $end->newPHPDateTime();
$min_day = $min_date->format('Y m d'); $min_day = $min_date->format('Y m d');
$max_day = $max_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; $show_end_date = false;
} }
$min_epoch = $this->getViewerDateFrom(); $min_epoch = $start->getEpoch();
$max_epoch = $this->getViewerDateTo(); $max_epoch = $end->getEpoch();
if ($this->getIsAllDay()) { if ($this->getIsAllDay()) {
if ($show_end_date) { if ($show_end_date) {
@ -803,6 +763,10 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
return $this->newDateTimeFromEpoch($epoch); return $this->newDateTimeFromEpoch($epoch);
} }
public function getStartDateTimeEpoch() {
return $this->newStartDateTime()->getEpoch();
}
public function newEndDateTime() { public function newEndDateTime() {
$datetime = $this->getParameter('endDateTime'); $datetime = $this->getParameter('endDateTime');
if ($datetime) { if ($datetime) {
@ -813,6 +777,10 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
return $this->newDateTimeFromEpoch($epoch); return $this->newDateTimeFromEpoch($epoch);
} }
public function getEndDateTimeEpoch() {
return $this->newEndDateTime()->getEpoch();
}
public function newUntilDateTime() { public function newUntilDateTime() {
$datetime = $this->getParameter('untilDateTime'); $datetime = $this->getParameter('untilDateTime');
if ($datetime) { if ($datetime) {

View file

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

View file

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