PHP and Default Timezones

Just in case anyone else runs into this I thought I’d record it for Google’s sake…

My business website was down. My web host was being non-helpful – “we’re aware there’s a problem and we’re working on it” – so there was nothing I could do but sleep on it and hope the site would be back up in the morning. When it finally came back online, I was faced with dozens of warnings like this:

Warning: strftime() [function.strftime]: It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘America/New_York’ for ‘EST/-5.0/no DST’ instead in [file name & line number]

Obviously they’d updated PHP or changed some settings.

Slightly panicked, a quick Google led to a bunch of solutions involving changing php.ini which I do not have access to because the site is on a shared host. I could probably have saved some time by, uh, you know, actually reading the warning.

The solution was to add a call the PHP function date_default_timezone_set() with one of the supported timezones in my config.php:

Oddly enough, the list of supported timezones for America does not include Ottawa, Ontario – the capital of Canada and fourth largest city in the country – but includes the tiny town of Swift Current, Saskatchewan [Pop. 15,000]. Quoi?