I have a general question about dealing with daylight saving time. I guess its not really PHP specific, but I am writing in PHP, so I figure it wouldn't hurt to include it.
I have a calendar app built using jquery fullcalendar. The user views events in their local timezone and my server stores them as UTC datetimes in mysql. (Other questions on stackoverflow suggest that this is the best way to deal with timezones.) So there is a conversion every time the user saves or views events on the calendar. This is working fine, but I am confused about how best to deal with daylight saving time.
For example, say a user in timezone EST (eastern standard time) creates an event when it is NOT daylight saving for 3pm that repeats everyday. My PHP code uses the standard DateTime (and DateTimeZone) class to convert between UTC and EST by UTC-5:00. When daylight saving is active, the clock turns ahead one hour and PHP will instead convert between UTC and EST by UTC-4:00. From the user's point of view, the event is then shifted from the original 3pm to 4pm. This is not what my users and I want. A 3pm event should stay a 3pm event regardless of daylight savings. What is the best way to deal with this? Is there a way in PHP to ignore daylight saving time?
My code:
$getDate = new DateTime($storedDate, new DateTimeZone('UTC'));
$getDate->setTimezone(new DateTimeZone('America/New_York'));
$getDateString = $getDate->format('Y-m-d H:i:s');
MORE INFO: (copied from my comments below)
-Only the first occurrence of a repeating event is stored. All other occurrences are created on the fly according to what calendar view the user requests (month,week,or day views). With the way I have it coded, it creates only the occurrences that will be visible on the view.
-The thing is, I also need to keep it constant for other timezones. To continue the original example, 3pm should stay 3pm in EST (regardless of daylight savings), but if the event is viewed in Central time, the event should also stay 2pm (regardless of daylight savings).
Essentially, I need to somehow ignore daylight saving time.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…