There is now direct way of doing that but you can hack together a method to accomplish that.
The idea is that you can specify time boundaries and limit the number of records and that's enough to do the job.
So setting the timeMin
to now (or right after your reference event end date), timeMax
to a big enough number, like a year from timeMin and maxResults
= 1 will get the next instance if it exists.
Here is how this can be done in nodejs:
let startDate = startTime ? new Date(startTime) : new Date()
let endDate = endTime ? new Date(endTime) : new Date(startDate.getTime() + 12 * 31 * 24 * 60 * 60 * 1000) // 1 year ahead
let startDateISO = startDate.toISOString()
let endDateISO = endDate.toISOString()
let result = await calendar.events.instances({
calendarId: "primary",
eventId: masterEventId,
maxResults: 1,
timeMin: startDateISO,
timeMax: endDateISO,
orderBy: "startTime",
timeZone: "UTC"
})
let nextInstance = res.data.items[0]
Similarly you can get previous instance if you order results in descending order and reverse the time boundaries (set timeMin
to a year back and timeMax
before the start of the reference event).