Google Calendar and Daylight Savings
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:
- 1-2:30 AM - Gets converted to 1-3:30 AM
- 1-3:30 AM - Remains the same
- 2-3 AM - Gets converted to 3-3 AM
- 2:15-2:45 AM - Gets converted to 3:15-3:45 AM
- 2:30-3 AM - Error message: "Oops, we couldn't create this event, please try again in a few minutes"
- 2:30-3:15 AM - Error message: "Oops, we couldn't create this event, please try again in a few minutes"
- 2:30-3:45 AM - Gets converted to 3:30-3:45 AM
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)