googleworkspace / apps-script-samples

Apps Script samples for Google Workspace products.
https://developers.google.com/apps-script
Apache License 2.0
4.49k stars 1.83k forks source link

solutions/automations/vacation-calendar/ fails to import events that are created too far in advance #474

Open wangd opened 1 month ago

wangd commented 1 month ago

Summary

The code in solutions/automations/vacation-calendar/Code.js uses lastRun to constrain the event search, but only imports events that are timed between now and MONTHS_IN_ADVANCE months from now. Hence, these events never get imported because when they satisfy the updatedMin parameter constraint in the Calendar.Events.list call, they fail the timeMin and timeMax constraint.

Expected Behavior

The code would import events, even events created a long time ago, if they occur within the search period (now, now+MONTHS_IN_ADVANCE).

Sample URL: https://github.com/googleworkspace/apps-script-samples/blob/main/solutions/automations/vacation-calendar/Code.js Description:

Actual Behavior

The code only imports events if they were created within MONTHS_IN_ADVANCE of their occurrence. Other events are skipped entirely.

Steps to Reproduce the Problem

  1. Create a vacation event for a date 4 months from now.
  2. Let the script run.
  3. Notice that the event is not imported and is never imported.

Proposal

While the optSince parameter in findEvents is useful in further demonstrating the Calendar.Events.list API call, and generally reduces execution cost, it seems to prevent one important expected behavior for a team vacation populator---that events planned far in advance will show up in the team calendar. I suggest three alternatives: