by Fran T
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:
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:
Version 2: Add past event count
Version 5: Eliminate use of dateParts() to simplify the flow and fix a problem when multiday events span a month boundary.
Version 6: Fixed another edge case with all-day events.
Reviews and ratings can be submitted in the app.