Events created using the Advanced Calendar API not showing up on Google Calendar Android app

Viewed 112

I'm adding all-day events to a calendar using the following code:

function main() {
  const response = JSON.parse(UrlFetchApp.fetch(API_URL).getContentText());
  const forecasts = response.daily;

  deleteEvents_();
  forecasts.forEach(e => {
    const forecast = new Forecast(e);
    console.log(JSON.stringify(forecast));
    console.log(forecast.getForecastText());
    Calendar.Events.insert(createEvent_(forecast.getForecastText(), forecast.date), CAL_ID);
  });
}

function createEvent_(summary, date) {
  const formattedDate = DateUtils.toYYYYMMDD(date, "-");
  return {
    summary: summary,
    start: {
      date: formattedDate
    },
    end: {
      date: formattedDate
    },
    transparency: "transparent"
  };
}

function deleteEvents_() {
  const today = new Date();
  const from = DateUtils.addDays(today, -1);
  const to = DateUtils.addDays(today, 7);
  console.log(`Retrieving events from ${from} to ${to}`);
  Calendar.Events.list(CAL_ID, {timeMin: from.toISOString(), timeMax: to.toISOString()}).items.forEach(event => {
    console.log(`Deleting: ${event.summary}`);
    Calendar.Events.remove(CAL_ID, event.id);
  })
}

I can see the events on the web version of Google Calendar but they don't show up on the app. I created another all-day event manually to test, and the one I created manually shows up on both the web version and the app. So next I got the properties of the manually-added event and one of the events I created via my script to see if there was any difference using Calendar.Events.list(CAL_ID, {timeMin: new Date("2022-04-30").toISOString(), timeMax: new Date("2022-05-01").toISOString()});.

Manually-created event:

{
  id: 'xxxxxxxx',
  creator: { email: 'xxxxxxxx@gmail.com' },
  end: { date: '2022-05-01' },
  created: '2022-05-01T00:49:18.000Z',
  etag: '"xxxxxxxx"',
  kind: 'calendar#event',
  organizer: {
     email: 'xxxxxxxx@group.calendar.google.com',
     displayName: 'weather',
     self: true },
  reminders: { useDefault: false },
  htmlLink: 'https://www.google.com/calendar/event?eid=xxxxxxxx',
  summary: 'test',
  transparency: 'transparent',
  updated: '2022-05-01T00:49:18.774Z',
  sequence: 0,
  start: { date: '2022-04-30' },
  iCalUID: 'xxxxxxxx@google.com',
  status: 'confirmed',
  eventType: 'default'
}

Script-created event:

{
  creator: { email: 'xxxxxxxx@gmail.com' },
  updated: '2022-05-01T00:28:26.176Z',
  htmlLink: 'https://www.google.com/calendar/event?eid=xxxxxxxx',
  created: '2022-05-01T00:28:26.000Z',
  sequence: 0,
  start: { date: '2022-05-01' },
  reminders: { useDefault: false },
  eventType: 'default',
  status: 'confirmed',
  etag: '"xxxxxxxx"',
  iCalUID: 'xxxxxxxx@google.com',
  end: { date: '2022-05-01' },
  organizer: { 
     self: true,
     email: 'xxxxxxxx@group.calendar.google.com',
     displayName: 'weather' },
  id: 'xxxxxxxx',
  summary: ' (12.97℃-16.41℃)',
  transparency: 'transparent',
  kind: 'calendar#event'
}

Sorry for the difference in the order of the JSON contents, I copied and pasted the response Google Apps Script gave me (except that I redacted IDs for privacy). But I don't see anything that could result in one being displayed in the Google Calendar Android app and the other not. Am I missing something? What else can I check?

1 Answers

As suggested by @ziganotschka, for all-day events, it seems that if the start and end date are the same, they display on calendar.google.com, but not in the Android app.

However, if you offset the end date forward by one day (as in the manually created example), it seems to display correctly on both the website and the app.

This was hinted at in the provided JSON events:

// manual event
  end: { date: '2022-05-01' },
  ...
  start: { date: '2022-04-30' },

// script event
  start: { date: '2022-05-01' },
  ...
  end: { date: '2022-05-01' },
Related