PHP5 time zones support

Posted by Dave Redfern (Writer), News on 18 Jul 2008 @ 21:19

With PHP5.1 and then into PHP5.2 it became important to set the timezone that the system was running in. Previously this would be inferred, but with version 5.2 not setting the timezone in either the environment, php.ini or at the apache level raises an E_STRICT warning (see: Changes in PHP datetime support). With these changes, some timezones were dropped altogether (see: PHP Manual: Other Timezones).

This has become most apparent through unit testing with PHPUnit on a separate project. As this could cause issues on systems where the timezone is not set, or not correctly set; the Scorpio framework has been updated to support setting this within the initialisation process through the use of the function: date_default_timezone_set().

By default the system will use UTC as the timezone. You can change this by specifying the timezone in the main config.xml file under system. The param is "timezone".

For example, to set the timezone to London, UK add the following to the config.xml file:

The full section will then look like:


	

The timezone is set at a framework level, and not per site; though in theory you can override it. Of course you can always manually specify the timezone using the date_default_timezone_set() function.

Please note: the timezone is initialised during the framework start up process and is the last instruction processed by system.inc in the system::init() pass. As such, the timezone will be set before any database connections or logging is done. Therefore changing the timezone may cause weirdness in your logs. As such it will not be overridden by the MVC system.

An incorrect timezone, either invalid or deprecated, will cause an E_NOTICE error to be raised. The set does use @ to suppress errors, but you should check that a valid timezone is entered before running the system.

From the latest docs, UTC is the only valid timezone from the "others" page. If you require GMT or GMT-0 you should use UTC.

< Return to article