diff --git a/src/applications/calendar/import/PhabricatorCalendarImportEngine.php b/src/applications/calendar/import/PhabricatorCalendarImportEngine.php --- a/src/applications/calendar/import/PhabricatorCalendarImportEngine.php +++ b/src/applications/calendar/import/PhabricatorCalendarImportEngine.php @@ -403,6 +403,9 @@ $until_datetime->setViewerTimezone($timezone); $event->setUntilDateTime($until_datetime); } + + $count = $rrule->getCount(); + $event->setParameter('recurrenceCount', $count); } return $event; 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 @@ -633,6 +633,11 @@ PhabricatorCalendarEvent $event, $raw_limit) { + $count = $event->getRecurrenceCount(); + if ($count && ($count <= $raw_limit)) { + return ($count - 1); + } + return $raw_limit; } 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 @@ -226,10 +226,16 @@ return null; } + $limit = $sequence + 1; + $count = $this->getRecurrenceCount(); + if ($count && ($count < $limit)) { + return null; + } + $instances = $set->getEventsBetween( null, $this->newUntilDateTime(), - $sequence + 1); + $limit); return idx($instances, $sequence, null); } @@ -907,9 +913,24 @@ $rrule->setUntil($until); } + $count = $this->getRecurrenceCount(); + if ($count) { + $rrule->setCount($count); + } + return $rrule; } + public function getRecurrenceCount() { + $count = (int)$this->getParameter('recurrenceCount'); + + if (!$count) { + return null; + } + + return $count; + } + public function newRecurrenceSet() { if ($this->isChildEvent()) { return $this->getParentEvent()->newRecurrenceSet();