title: How can I check if there are conflicts for recurring events using Apps Script?
body: <p>I would like to write a Google Apps Script that will check if there are any conflicts for a recurring events before I send it to Google Calendar from a Google Sheet.</p>
  
  <p>I am able to check on the first date using:</p>
  
  <pre><code>var ConTimes = calendarAll.getEvents(startDate, endDate, {search: roomNumber});
  Logger.log('Conflicting Times: ' + ConTimes.length);
  Logger.log('Conflicting dates: ' + ConTimes);
  </code></pre>
  
  <p>If the length is greater than 0, then I know there is a conflict; however, this script will not check any of the recurring events. </p>
  
  <p>It would be nice if there was a simple script that would search for all Calendar events with a specific word, and then return the number of overlapping events between the current Calendar events and the recurring events I would like to schedule.  I imagine this ideal script would be similar to the one I use for adding the recurring events:</p>
  
  <pre><code>var recurrence = CalendarApp.newRecurrence().addWeeklyRule().onlyOnWeekdays(weekdays).times(times);  
  var eventSeries = calendarSingle.createEventSeries(newEventTitle, startDate, endDate, recurrence);
  </code></pre>
  
  <p>In my spreadsheet, I have these columns:row-data for example:</p>
  
  <ul>
  <li>RoomNumber:  4000; </li>
  <li>EventName:   Geology101; </li>
  <li>Start DateTime: 7/23/2018   12:00:00; </li>
  <li>End DateTime: 7/23/2018 14:00:00; </li>
  <li>RecDaysPerWeek: MONDAY, WEDNESDAY, FRIDAY; </li>
  <li>NumberOfWeeks: 4.</li>
  </ul>
  
  <p>I'm sure I  can write a long script that will give me all the dates for the Mondays, Wednesdays, and Fridays over the next 4 weeks, and then check if each date has a conflict, but this is costly.  Has anyone seen if Google has a code written for searching recurrences?</p>
  
  <p>Thanks. 
  +++++++++Some Edits for Clarification+++++++++++
  I'm not sure if I explained this clearly enough, so here is a sample of what the costly code would look like and produce:</p>
  
  <pre><code>var startDate=Mon Jul 23 2018 07:22:11 GMT-0400 (EDT);
  var endDate=Mon Jul 23 2018 08:22:11 GMT-0400 (EDT);
  var times=4;
  var recurringDays="MONDAY, WEDNESDAY, FRIDAY";
  var room = "5071";
  
  if (recurringDays == "MONDAY, WEDNESDAY, FRIDAY") {
  
  for (var i = 1; i &lt; times; i++)  {   
    //Note: this assumes the first weekday and the start date are the same
    // Then what is the date of the first Monday
    var MondayStartDate = startDate;
    var MondayEndDate = endDate;  
         var ConTimes = calendarAll.getEvents(startDate, endDate, {search: room});
              Logger.log('Conflicting Times: ' + ConTimes.length);   
    //and what are the dates of the first Wednesday
    var WednesdayStartDate = startDate.setDate(startDate.getDate()+2);
    var WednesdayEndDate = endDate.setDate(endDate.getDate()+2);
         var ConTimes = calendarAll.getEvents(startDate, endDate, {search: room});
              Logger.log('Conflicting Times: ' + ConTimes.length); 
    //and what is the date of the first Friday
    var FridayStartDate = startDate.setDate(startDate.getDate()+2);
    var FridayEndDate = endDate.setDate(endDate.getDate()+2); 
         var ConTimes = calendarAll.getEvents(startDate, endDate, {search: room});
              Logger.log('Conflicting Times: ' + ConTimes.length); 
    var     Back2MonStartDate = startDate.setDate(startDate.getDate()+3);
    var     Back2MonEndDate = endDate.setDate(endDate.getDate()+3);      
   } }
  </code></pre>
  
  <p>The script produces a log that looks like this:</p>
  
  <ul>
  <li>[18-07-23 13:36:44:551 EDT] times: 5</li>
  <li>[18-07-23 13:36:44:552 EDT] room: room 5071</li>
  <li>[18-07-23 13:36:44:634 EDT] Conflicting Times: 2</li>
  <li>[18-07-23 13:36:44:682 EDT] Conflicting Times: 2</li>
  <li>[18-07-23 13:36:44:746 EDT] Conflicting Times: 2</li>
  <li>[18-07-23 13:36:44:806 EDT] Conflicting Times: 2</li>
  <li>[18-07-23 13:36:44:878 EDT] Conflicting Times: 2</li>
  <li>[18-07-23 13:36:44:948 EDT] Conflicting Times: 2</li>
  <li>[18-07-23 13:36:45:017 EDT] Conflicting Times: 2</li>
  <li>[18-07-23 13:36:45:091 EDT] Conflicting Times: 2</li>
  <li>[18-07-23 13:36:45:158 EDT] Conflicting Times: 2</li>
  <li>[18-07-23 13:36:45:234 EDT] Conflicting Times: 2</li>
  <li>[18-07-23 13:36:45:322 EDT] Conflicting Times: 2</li>
  <li>[18-07-23 13:36:45:371 EDT] Conflicting Times: 2</li>
  </ul>
  
  <p>I would have to write the for loop script for every combination of day (e.g."MONDAY, WEDNESDAY, FRIDAY") and run the getEvents search for each day. </p>
  
  <p>From the log file, I can actually find which day on my calendar has the conflicting day (e.g. the third "2" is the first Friday after the start day.  </p>
  
  <p>If there is no significantly shorter Google Apps Script that reduces the number of getEvents searches, then I guess this script is what I need to write.  </p>
  
  <p>Thanks for the help.</p>