diff --git a/src/applications/calendar/import/PhabricatorCalendarImportEngine.php b/src/applications/calendar/import/PhabricatorCalendarImportEngine.php index aaedf3e2fd..0b91a6244c 100644 --- a/src/applications/calendar/import/PhabricatorCalendarImportEngine.php +++ b/src/applications/calendar/import/PhabricatorCalendarImportEngine.php @@ -403,6 +403,9 @@ abstract class PhabricatorCalendarImportEngine $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 index 9949ee2f5a..5c6b34c9fb 100644 --- a/src/applications/calendar/query/PhabricatorCalendarEventQuery.php +++ b/src/applications/calendar/query/PhabricatorCalendarEventQuery.php @@ -633,6 +633,11 @@ final class PhabricatorCalendarEventQuery 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 index 64bdf07d46..37b45a2a3f 100644 --- a/src/applications/calendar/storage/PhabricatorCalendarEvent.php +++ b/src/applications/calendar/storage/PhabricatorCalendarEvent.php @@ -226,10 +226,16 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO 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 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO $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();