I have a general question about working with daylight saving time. I assume that this is not very specific PHP, but I write in PHP, so I believe that this will not hurt to include it.
I have a calendar application built using jquery fullcalendar. A user views events in their local time zone, and my server stores them as UTC time in mysql. (Other questions about stackoverflow suggest that this is the best way to deal with time zones.) Thus, a conversion occurs each time a user saves or views events on a calendar. It works great, but I'm confused about how best to deal with summer time.
For example, let's say a user in the EST time zone (Eastern Standard Time) creates an event when it is not a summer day for 3 hours, which is repeated every day. My PHP code uses the standard DateTime class (and DateTimeZone) to convert between UTC and EST to UTC-5: 00. When daylight saving time is active, the clock rotates one hour, and instead, PHP will convert between UTC and EST by UTC-4: 00. From the point of view of the user, the event then shifts from the original 3 pm to 4 pm. This is not what my users and I want. The 3pm event should remain at 3pm, regardless of daylight saving time. What is the best way to handle this? Is there a way in PHP to ignore daylight saving time?
My code is:
$getDate = new DateTime($storedDate, new DateTimeZone('UTC')); $getDate->setTimezone(new DateTimeZone('America/New_York')); $getDateString = $getDate->format('Ymd H:i:s');
FURTHER INFORMATION: (copied from my comments below)
- The first occurrence of a recurring event is saved one time. All other events are created "on the fly" in accordance with a calendar view of user requests (month, week or day). With the way I encoded it, it only creates entries that will be visible in the view.
“The thing is, I also need to keep it constant for other time zones.” To continue the original example, 3 pm should remain for 3 hours in EST (regardless of daylight saving time), but if the event is viewed at central time, the event should also remain for 2 hours (regardless of daylight saving).
Essentially, I need to somehow ignore daylight saving time.
php datetime dst
train
source share