One of my requirements for my current project is to allow the user to select the time zone for his account, and then use this time zone for all date and time related functions on the entire site.
As I see it, I have two options:
- Pass the DateTimeZone object to the DateTime constructor for each new DateTime
- Set default timezone with PHP
date_default_timezone_set()
It seems that using date_default_timezone_set is the way to go, but I'm not sure where exactly I should install it. Since the time zone will be different from user to user, and DateTime is used throughout the site, I need to set it somewhere so that it affects all pages.
Perhaps I could write an event listener that installs it after a successful login? If I take this approach, will it remain installed on all pages or will it be installed only for each page?
I would like to hear how others will approach this.
source share