How to find out whether two "Events" overlap using "Start" and "End" datetime objects. Python

415 views Asked by At

I am using the Google calendar API with Python, in order to compile events on a given day, to see how much time I spend on certain events per day/week etc.

I was originally just subtracting the End time from the Start time to achieve a Duration, and then adding all event Duration on a given day.

The thing is, sometimes I overlap events, for example Lunch and Reading might overlap and then cause the program to believe I've magically spent an extra 30 minutes in a day.

The google API gives (as can be seen here) the following values amongst others:

  "start": {
    "date": date,
    "dateTime": datetime,
    "timeZone": string
  },
  "end": {
    "date": date,
    "dateTime": datetime,
    "timeZone": string

So if I have a long list of Event objects, that all have a Start and End time, what would be a good way of checking that there are Event overlaps?

0

There are 0 answers