Calendar API Demo

by Fran T

Version 6 (April 23, 2018)

Download (26 downloads)

Despite the ease of use of the Calendar blocks, there are inconsistencies in Google's internal API that result in it being very tricky just to get your events for the day. All-day events cause special difficulty, which we delve into in this Forum thread:

https://groups.google.com/forum/m/#!topic/automate-user/JfGZl5gLoFY

Some things to watch out for:

o All-day events that start on the following day are returned within the window of the current day and must be filtered out, first converting their beginning and ending times to the GMT (UTC) time zone.
o The beginning and ending times in the Has Event block are both inclusive and have one-second resolution, so the number of seconds in a day since midnight *minus one* (86399) must be used for the ending date to return results only for the current day.
o Care must be taken not to filter out multiday events inappropriately.

In light of all these "gotchas", I wrote this demo to figure out the best way to resolve them in my flows. It's written as a subroutine to make it easier to copy into your own flows. (You will also need to copy the Has Event block.) The subroutine consumes the calendarEvents value from the Has Event block, and returns pastEventCount, upcomingEventCount, and ongoingEventCount. To set up the subroutine, set those three variables to zero before invoking the subroutine for the first time. That way, they'll be cumulative over the subroutine invokations. In other words, those values will reflect the total upcoming and ongoing events for all the calendars you check. -For example, for all the events you have today, you might want to call the subroutine for your personal, work, and Holiday calendars.

As an experiment, try adding an all-day event for tomorrow to your calendar and note the difference in counts between what the Has Event block returns and what this subroutine calculates.

I hope this flow helps you as much as it helped me!

To see it in action, you can check out my updated version of the "morning app" JARVIS flow here:

http://llamalab.com/automate/community/flows/17289

Enjoy!

5.0 average rating from 1 reviews

5 stars
1
4 stars
0
3 stars
0
2 stars
0
1 star
0
Warnings
0

Reviews and ratings can be submitted in the app.