开发者

Shouldn't changing a user's Drupal locale also change $user->timezone?

I must be missing something really obvious here:

I have a user whose locale is set to America/Los Angeles. When I look in the 'users' database table, they have a value of -28800 for the timezone field. This makes sense; 8 hours before GMT = -开发者_如何学Go28800 seconds.

But now, when the user changes his locale to America/New York, the value of timezone stays the same, rather than switching to -18000, 5 hours before GMT. Why isn't this change happening? If I'm looking in the wrong place, where would I find a timezone value that matches their locale?

The server's timezone is also set to America/Los Angeles, if that matters. Thanks!


Sounds like a bug. What version of Drupal? Either way, you should be able to fix it fairly easily with hook_user. You'll need to do a user_save and explicitly define the new timezone value. It'd be something like this:

function trnAccount_user($op, &$edit, &$account, $category = NULL) {

switch($op) {
case 'update':
  user_save($account, array('timezone' => $myTimeZone);
break;
}

$myTimeZone is a placeholder. Do a print_r on the incoming $edit within this hook and you should be able to find where the timezone change has been recorded then just replace $myTimeZone with that array path (for example... $edit['values']['timezone']). If its not coming through at all then something is wrong with the form you're using the change the locale.

If you're using a form you wrote yourself, you could also handle this in the submit function for that form.


ARGGH -- FALSE ALARM. Just as I was wrapping all this up, I thought it might be worth checking another of my Drupal sites to see what happens with $user->timezone there. Turns out that it's working correctly -- change the locale in the user edit page and $user->timezone changes as it ought to. Thus, I'm screwing the pooch somewhere in my current site; Drupal itself seems to be OK. Apologies for wasting your time; but many thanks in any case.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜