Posted by jredding on January 6, 2009 at 4:16am
In userpoints.module at line 1537 we have the following function
function userpoints_date_to_timestamp($date) {
//This takes the FAPI date form array and returns a timestamp
if ($date) {
return mktime(0, 0, 0, $date['month'], $date['day'], $date['year']);
}
}The function works just fine and does exactly what its supposed to do BUT it throws an exception when run through simpletest. The following error is reported
mktime() [function.mktime]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable 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' insteadI understand we can safely ignore this but I would rather not. We do have
variable_get('date_default_timezone', 0);so we can get the site's default timezone and use this.
anyhow what's the proper way of getting rid of this error?

Comments
When I encountered this for
When I encountered this for a site that had extremely old code base and wanted to run on PHP5, I used the following:
<?php
ini_set('date.timezone', 'America/New_York');
?>
Or better yet:
<?phpif (!ini_get('date.timezone')) {
ini_set('date.timezone', 'America/New_York');
}
?>
However, this imposes the above timezone on all site users, which may not work for a site that allows users to have different time zones. Since we are doing "days" and not hours, this may be OK.
If you want to take it further.
In Drupal itself, we have the following variables: configurable_timezones (true/false), sitewide_timezone (?). and date_default_timezone, which contains something like
s:6:"-14400";(number of seconds offset from UTC). In addition to that the users table has a timezone column like so -18000 (also UTC offset).So, ideally, it would be something that checks the timezones, you can check if
$user->timezonehas a value, and if not, usevariable_get('date_default_timezone', 0). But we need to convert that, via a table, to a timezone string. See comments here http://www.php.net/manual/en/function.date-default-timezone-set.phpDrupal performance tuning, development, customization and consulting: 2bits.com, Inc..
Personal blog: Baheyeldin.com.
Drupal performance tuning, development, customization and consulting: 2bits.com, Inc..
Personal blog: Baheyeldin.com.
This worked for me
When I put the snippet:
if (!ini_get('date.timezone')) {ini_set('date.timezone', 'America/New_York');
}
At the very beginning of index.php (I know, hackish no-no!).
But I'm running D6.13, and the error's thrown at line 848 of node module, so it's not all down to an old code base.
Same problem with
Same problem with token_node.inc. Line 48 problem with timezone. Filed a reply on: http://drupal.org/node/307520#comment-2448248. Greetings, Martijn
Another solution
Put the following in settings.php:
ini_set('date.timezone', date_default_timezone_get());
"God gave us two ears and one mouth to remind us we should listen twice as much as we talk."
Great solution. Thanks for
Great solution. Thanks for sharing. It's solved my timezone issue in token module. Think this is better than hacking modules.
A million Thanks --- fixed
A million Thanks --- fixed the terrible error!
Best solution
thanks for this! we really appreciate it!
Best Solution!
It works!
Many thanks.
Thank you very much
it work fine. Thank you very much,
HOANG BIEN
Didn't work for me
Had this problem on several sites, and the above fix just made things worse (additional errors.) Adding date.timezone = "America/Los_Angeles" to php.ini did the trick though.
Thank You !!!!
Worked Perfectly!!