Bug #630
PHP 5.1+ generates "date_default_timezone_set" warning on every page
| Status: | Closed | Start date: | 01/01/2010 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | Ryan Gordon | % Done: | 100% | |
| Category: | PHP | |||
| Target version: | 1.4.14 | |||
| Reproducibility: | Always | Database Type: | ||
| Reported In MyBB Version: | 1.6.0 | Database Version: | ||
| PHP Version: | 5.3 | SQA assignments: | ||
| Browser: |
Description
In PHP 5.1, all calls to date/time functions in PHP will generate a notice (below) when the default time zone is not set. Because in MyBB we're handling time zones internally, we just need to add something like:
if(function_exists('date_default_timezone_set'))
{
date_default_timezone_set('GMT');
}
This would need to go in all of the usual init places: inc/init.php, install/index.php, install.upgrade.php.
History
#1 Updated by Stefan T. over 3 years ago
I think the warning occurs only when it is not set in the php configuration?
#2 Updated by Tom Moore over 3 years ago
That's true; only if PHP isn't configured correctly. We could make sure that the timezone is set when MyBB is installed though, and show a warning if it isn't?
#3 Updated by Chris Boulton over 3 years ago
It's not a case of PHP being configured incorrectly. By default, it's commented out in the production php.ini supplied in the official sources (http://svn.php.net/repository/php/php-src/branches/PHP_5_3_2/php.ini-production).
It also needs to be considered from the POV of shared hosts, where a user cannot change a php.ini setting.
It's a simple three line modification, and the changes just need to be exactly that. Of course, the alternative for 1.6 is to stop using the my_* date associated functions and change everything to normal date functions with date_default_timezone_set(), but that's not a change I'm comfortable with having in at this late stage and keep in mind that date_default_timezone_set() can only ever be called once.
#4 Updated by Ryan Gordon over 3 years ago
Tom Moore wrote:
That's true; only if PHP isn't configured correctly. We could make sure that the timezone is set when MyBB is installed though, and show a warning if it isn't?
As I believe chris mentioned, even if we did provide a warning to the user during install or upgrade, shared hosting environments will be reluctant to make those type of changes.
I believe in addition to the fix, we should check to see if it is set or not in the php.ini first? Otherwise, we would be overriding it?
#5 Updated by Chris Boulton over 3 years ago
It wouldn't matter either way - but I'd say it's probably better to have all copies of MyBB running under the exact same setting to rule out any potential issues where servers may be in different time zones?
#6 Updated by Huji Lee over 3 years ago
But if the server is located in a special time zone and the php.ini file is set accordingly, then the user who sets up a forum for a different time zone (using time zone offset) may have a problem.
Example: Server time is not set to GMT but to GMT-1. A user tries to set up a forum for GMT+5:30 zone. By applying the change mentioned above, the user needs to practically use a GMT+6:30 offset, which is not available in MyBB options.
#7 Updated by Chris Boulton over 3 years ago
The change will not alter the MyBB date calculation behavior at all. MyBB calculates all dates using gmdate, which is not affected by the date.timezone setting in PHP.
#8 Updated by Ryan Gordon over 3 years ago
- Category set to PHP
- Status changed from New to Assigned
- Assignee set to Ryan Gordon
- Target version set to 1.6.0 Beta
#9 Updated by Ryan Gordon over 3 years ago
- Status changed from Assigned to Resolved
- % Done changed from 0 to 100
Applied in changeset r4741.
#10 Updated by Stefan T. over 3 years ago
- Status changed from Resolved to Closed
#11 Updated by Ryan Gordon about 3 years ago
- Target version changed from 1.6.0 Beta to 1.4.14
#12 Updated by Severin Pick almost 3 years ago
I'm sorry to interrupt you, but when you include the board into your homepage, "date_default_timezone_set" resets the timezone for the whole page, that means asking for the date() will always give you the time in GMT.
Instead of the given code, something like this should be used:
if(function_exists('date_default_timezone_set') AND (!ini_get('date.timezone')))
{
date_default_timezone_set('GMT');
}
Now the timezone only gets reset, if it hasn't alredy been defined by the php.ini
#13 Updated by Ryan Gordon almost 3 years ago
- Status changed from Closed to Feedback
#14 Updated by Ryan Gordon almost 3 years ago
- Status changed from Feedback to Resolved
Applied in changeset r5080.
#15 Updated by Ryan Gordon almost 3 years ago
Thank you for reporting that issue
#16 Updated by Stefan T. almost 3 years ago
- Status changed from Resolved to Closed