diff --git a/src/applications/calendar/controller/PhabricatorCalendarEventViewController.php b/src/applications/calendar/controller/PhabricatorCalendarEventViewController.php --- a/src/applications/calendar/controller/PhabricatorCalendarEventViewController.php +++ b/src/applications/calendar/controller/PhabricatorCalendarEventViewController.php @@ -27,8 +27,8 @@ $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'), diff --git a/src/applications/calendar/editor/PhabricatorCalendarEventEditEngine.php b/src/applications/calendar/editor/PhabricatorCalendarEventEditEngine.php --- a/src/applications/calendar/editor/PhabricatorCalendarEventEditEngine.php +++ b/src/applications/calendar/editor/PhabricatorCalendarEventEditEngine.php @@ -155,6 +155,13 @@ } 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 @@ ->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; } diff --git a/src/applications/calendar/query/PhabricatorCalendarEventQuery.php b/src/applications/calendar/query/PhabricatorCalendarEventQuery.php --- a/src/applications/calendar/query/PhabricatorCalendarEventQuery.php +++ b/src/applications/calendar/query/PhabricatorCalendarEventQuery.php @@ -99,7 +99,7 @@ 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 @@ $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 @@ $start = $this->rangeBegin; } else { - $start = $event->getViewerDateFrom() - $duration; + $start = $event->getStartDateTimeEpoch() - $duration; } $date = $start; @@ -238,9 +238,9 @@ 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 @@ } } - $events = msort($events, 'getViewerDateFrom'); + $events = msort($events, 'getStartDateTimeEpoch'); return $events; } @@ -500,7 +500,7 @@ } } - $events = msort($events, 'getViewerDateFrom'); + $events = msort($events, 'getStartDateTimeEpoch'); return $events; } @@ -510,8 +510,8 @@ $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]); diff --git a/src/applications/calendar/query/PhabricatorCalendarEventSearchEngine.php b/src/applications/calendar/query/PhabricatorCalendarEventSearchEngine.php --- a/src/applications/calendar/query/PhabricatorCalendarEventSearchEngine.php +++ b/src/applications/calendar/query/PhabricatorCalendarEventSearchEngine.php @@ -343,8 +343,8 @@ $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 @@ $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); diff --git a/src/applications/calendar/storage/PhabricatorCalendarEvent.php b/src/applications/calendar/storage/PhabricatorCalendarEvent.php --- a/src/applications/calendar/storage/PhabricatorCalendarEvent.php +++ b/src/applications/calendar/storage/PhabricatorCalendarEvent.php @@ -49,8 +49,6 @@ private $parentEvent = self::ATTACHABLE; private $invitees = self::ATTACHABLE; - private $viewerDateFrom; - private $viewerDateTo; private $viewerTimezone; // Frequency Constants @@ -273,46 +271,8 @@ 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 @@ * @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 @@ 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 @@ $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 @@ return $this->newDateTimeFromEpoch($epoch); } + public function getStartDateTimeEpoch() { + return $this->newStartDateTime()->getEpoch(); + } + public function newEndDateTime() { $datetime = $this->getParameter('endDateTime'); if ($datetime) { @@ -813,6 +777,10 @@ return $this->newDateTimeFromEpoch($epoch); } + public function getEndDateTimeEpoch() { + return $this->newEndDateTime()->getEpoch(); + } + public function newUntilDateTime() { $datetime = $this->getParameter('untilDateTime'); if ($datetime) { diff --git a/src/applications/people/controller/PhabricatorPeopleProfileViewController.php b/src/applications/people/controller/PhabricatorPeopleProfileViewController.php --- a/src/applications/people/controller/PhabricatorPeopleProfileViewController.php +++ b/src/applications/people/controller/PhabricatorPeopleProfileViewController.php @@ -205,8 +205,8 @@ $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) diff --git a/src/applications/people/query/PhabricatorPeopleQuery.php b/src/applications/people/query/PhabricatorPeopleQuery.php --- a/src/applications/people/query/PhabricatorPeopleQuery.php +++ b/src/applications/people/query/PhabricatorPeopleQuery.php @@ -432,7 +432,7 @@ while (true) { foreach ($events as $event) { $from = $event->getDateFromForCache(); - $to = $event->getViewerDateTo(); + $to = $event->getEndDateTimeEpoch(); if (($from <= $cursor) && ($to > $cursor)) { $cursor = $to; continue 2;