I have tried a lot of things to combine 2 calendars and none of them seem to work. On their own things work great. I would love them to stay in order by date when joined if possible.
This works great on it's own.
var cal = CalendarApp.getCalendarById(mycal);
var events = cal.getEvents(new Date(StartDate), new Date(EndDate), {search: ""});
...
var details=[[events[i].getTitle(), events[i].getDescription(), events[i].getLocation(), events[i].getStartTime(), events[i].getEndTime(), events[i].getDateCreated(), events[i].getLastUpdated()]];
None of my attempts are working
var cal = CalendarApp.getCalendarById(mycal);
var cal2 = CalendarApp.getCalendarById(bCal);
var temp = cal.getEvents(new Date(StartDate), new Date(EndDate));
var temp2 = cal2.getEvents(new Date(StartDate), new Date(EndDate));
//Failed attempts
var events = temp temp2;
//or
var events = temp.join(temp2);
//or
var events = temp & temp2;
Please piont me in the correct direction.
CodePudding user response:
Try this:
function getCalEvents() {
var cal1 = CalendarApp.getCalendarById(mycal);
var cal2 = CalendarApp.getCalendarById(bCal);
var arr1 = cal1.getEvents(new Date(StartDate), new Date(EndDate));
var arr1 = cal2.getEvents(new Date(StartDate), new Date(EndDate));
var arr3 = arr1.concat(arr2);
arr3.sort((a, b) => {return a.getStartTime().valueOf() - b.getStartTime().valueOf()});
}