Scheduling & DST

前端 未结 3 1196
星月不相逢
星月不相逢 2021-01-05 02:48

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 accor

3条回答
  •  别那么骄傲
    2021-01-05 03:25

    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.

提交回复
热议问题