Google Calendar and Daylight Savings

Nov 03, 2019
#random #cs


Yesterday was the end of daylight savings, which is when the clock jumps from 2 AM back to 1 AM. When daylight savings starts in the spring, the clock jumps from 2 AM directly to 3 AM. This raises the question of how Google calendar handles daylight savings. Today, I tried creating a couple events around 2 AM on 3/8/2020, which is when daylight savings starts next year. I got back the following results:

Based on these test cases, it seems that Google calendar's backend adds one hour to each of the start and end times if they fall within the daylight savings gap, and returns an error if the start time ends up later than the end. This behavior seems relatively easy to implement so it's not a bad choice, but it is strange to me that an event for 2:15-2:45 AM is well defined while an event for 2:15-3 AM is not. I think a better implementation would be that any event that starts or ends within the daylight savings gap should result in an error, since those times does not exist. Events that start before and end after the gap should remain unchanged. The implementation for this behavior is also simpler.

def google_add_event(start, end):
  if start.in_daylight_savings():
    start += 1 hour
  if end.in_daylight_savings():
    end += 1 hour
  if start > end:
    raise TimeException()
  create_event(start, end)

def my_add_event(start, end):
  if start.in_daylight_savings() or end.in_daylight_savings():
    raise TimeException()
  if start > end:
    raise TimeException()
  create_event(start, end)




Comment