} else {
            $utc_min = $row['dateFrom'];
            $utc_max = $row['dateTo'];
        }
    }
    $utc_until = $row['recurrenceEndDate'];
    $start_datetime = PhutilCalendarAbsoluteDateTime::newFromEpoch($utc_min);
    if ($is_all_day) {
        $start_datetime->setIsAllDay(true);
    }
    $end_datetime = PhutilCalendarAbsoluteDateTime::newFromEpoch($utc_max);
    if ($is_all_day) {
        $end_datetime->setIsAllDay(true);
    }
    if ($utc_until) {
        $until_datetime = PhutilCalendarAbsoluteDateTime::newFromEpoch($utc_until);
    } else {
        $until_datetime = null;
    }
    $parameters['startDateTime'] = $start_datetime->toDictionary();
    $parameters['endDateTime'] = $end_datetime->toDictionary();
    if ($until_datetime) {
        $parameters['untilDateTime'] = $until_datetime->toDictionary();
    }
    queryfx($conn, 'UPDATE %T SET parameters = %s WHERE id = %d', $table_name, phutil_json_encode($parameters), $row['id']);
}
// Generate UTC epochs for all events. We can't readily do this one at a
// time because instance UTC epochs rely on having the parent event.
$viewer = PhabricatorUser::getOmnipotentUser();
$all_events = id(new PhabricatorCalendarEventQuery())->setViewer($viewer)->execute();
foreach ($all_events as $event) {
 private function getRecurrenceWindowEnd(PhabricatorCalendarEvent $event, $generate_until)
 {
     $end_epochs = array();
     if ($generate_until) {
         $end_epochs[] = $generate_until;
     }
     $until_epoch = $event->getUntilDateTimeEpoch();
     if ($until_epoch) {
         $end_epochs[] = $until_epoch;
     }
     if (!$end_epochs) {
         return null;
     }
     return PhutilCalendarAbsoluteDateTime::newFromEpoch(min($end_epochs));
 }
 private function newDateTimeFromEpoch($epoch)
 {
     $datetime = PhutilCalendarAbsoluteDateTime::newFromEpoch($epoch);
     if ($this->getIsAllDay()) {
         $datetime->setIsAllDay(true);
     }
     return $this->newDateTimeFromDateTime($datetime);
 }
 public function newIntermediateEventNode(PhabricatorUser $viewer)
 {
     $base_uri = new PhutilURI(PhabricatorEnv::getProductionURI('/'));
     $domain = $base_uri->getDomain();
     $uid = $this->getPHID() . '@' . $domain;
     $created = $this->getDateCreated();
     $created = PhutilCalendarAbsoluteDateTime::newFromEpoch($created);
     $modified = $this->getDateModified();
     $modified = PhutilCalendarAbsoluteDateTime::newFromEpoch($modified);
     $date_start = $this->getDateFrom();
     $date_start = PhutilCalendarAbsoluteDateTime::newFromEpoch($date_start);
     $date_end = $this->getDateTo();
     $date_end = PhutilCalendarAbsoluteDateTime::newFromEpoch($date_end);
     if ($this->getIsAllDay()) {
         $date_start->setIsAllDay(true);
         $date_end->setIsAllDay(true);
     }
     $host_phid = $this->getHostPHID();
     $invitees = $this->getInvitees();
     foreach ($invitees as $key => $invitee) {
         if ($invitee->isUninvited()) {
             unset($invitees[$key]);
         }
     }
     $phids = array();
     $phids[] = $host_phid;
     foreach ($invitees as $invitee) {
         $phids[] = $invitee->getInviteePHID();
     }
     $handles = $viewer->loadHandles($phids);
     $host_handle = $handles[$host_phid];
     $host_name = $host_handle->getFullName();
     $host_uri = $host_handle->getURI();
     $host_uri = PhabricatorEnv::getURI($host_uri);
     $organizer = id(new PhutilCalendarUserNode())->setName($host_name)->setURI($host_uri);
     $attendees = array();
     foreach ($invitees as $invitee) {
         $invitee_phid = $invitee->getInviteePHID();
         $invitee_handle = $handles[$invitee_phid];
         $invitee_name = $invitee_handle->getFullName();
         $invitee_uri = $invitee_handle->getURI();
         $invitee_uri = PhabricatorEnv::getURI($invitee_uri);
         switch ($invitee->getStatus()) {
             case PhabricatorCalendarEventInvitee::STATUS_ATTENDING:
                 $status = PhutilCalendarUserNode::STATUS_ACCEPTED;
                 break;
             case PhabricatorCalendarEventInvitee::STATUS_DECLINED:
                 $status = PhutilCalendarUserNode::STATUS_DECLINED;
                 break;
             case PhabricatorCalendarEventInvitee::STATUS_INVITED:
             default:
                 $status = PhutilCalendarUserNode::STATUS_INVITED;
                 break;
         }
         $attendees[] = id(new PhutilCalendarUserNode())->setName($invitee_name)->setURI($invitee_uri)->setStatus($status);
     }
     $node = id(new PhutilCalendarEventNode())->setUID($uid)->setName($this->getName())->setDescription($this->getDescription())->setCreatedDateTime($created)->setModifiedDateTime($modified)->setStartDateTime($date_start)->setEndDateTime($date_end)->setOrganizer($organizer)->setAttendees($attendees);
     return $node;
 }