One of my requirements for my current project is to allow a user to choose a time zone for their account, and then use this time zone for all date/time related features throughout the entire site.
The way I see it, I have two options:
- Pass in a DateTimeZone object to DateTime's constructor for every new DateTime
- Set the default time zone using PHP's
date_default_timezone_set()
It seems like using date_default_timezone_set is the way to go, but I'm not sure exactly where I should set it. Because the time zone will be different from user to user and DateTime's are used all over the site, I need to set it somewhere that it will affect all pages.
Maybe I could write an event listener that sets it after a successful login? If I take this approach, will it stay set across all pages or is it only set on a per-page basis?
I'd love to hear how others would approach this.