googleworkspace / googleworkspace/apps-script-samples

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

Open
#474 0 comments 0 reactions 1 assignee View on GitHub

@vinay-google is already working on this.

Since Jul 10, 2024.

Dominant language
JavaScript
Stars
5.2k
Forks
2k
PR merge metrics
No merged PRs in 30d

Description

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:

  • Remove the updatedMin parameter in the findEvents body. That way, the code will still add upcoming events, but will add redundant events that get de-duplicated.
  • Set the default MONTHS_IN_ADVANCE relatively large, e.g., 12, 18 or more, so that the problem only manifests for events created much farther in advance.
  • Add a warning comment in the code that alerts the developer to the nature of these skipped imports and let the developer implement solution if desired.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.