Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scheduling & DST

I am writing a calendar/scheduling app in PHP. Right now I take the day of the week you want the event to occur on and the time. I also ask for the timezone and adjust accordingly to get the event time in GMT.

Then I store that time as an offset from midnight of the day of the show. This is fine and works great, but what happens when I hit daylight savings time? I'm not sure what to do when that happens. The other problem is that not all countries have DST so I'm kind of in a bind there.

I am displaying these events on a calendar, so timing is important.

like image 389
Gavin Schulz Avatar asked Feb 18 '09 22:02

Gavin Schulz


1 Answers

Dealing with DST is a real pain.

For future events you should store the location and the local time when the event is to occur, not the GMT time. This is because sometimes governments change when DST starts and stops (it just happened last year in the US) and the events then shift in GMT, but not in local time.

Then if you need to notify when the event is occurring, every day collect the events for the next 24-48 hrs and convert their times to GMT then. To do that, you need a location-timezone database like this one. Get the GMT offset for each location at the time of the event and use that to convert the time to GMT, then you know exactly when the event will occur.

like image 177
Carlos A. Ibarra Avatar answered Sep 19 '22 17:09

Carlos A. Ibarra