function date_timezone_user in Date 6
Same name and namespace in other branches
- 5.2 date_timezone/date_timezone.module \date_timezone_user()
- 6.2 date_timezone/date_timezone.module \date_timezone_user()
Update user timezone information at login.
This is to make sure that modules that rely on the timezone offset have current information to process.
File
- date_timezone/
date_timezone.module, line 140 - This module will make the alter the user and site timezone forms to select a timezone name instead of a timezone offset.
Code
function date_timezone_user($op, &$edit, &$account, $category = NULL) {
if ($account->uid && $op == 'login' && variable_get('configurable_timezones', 1)) {
if (strlen($account->timezone_name)) {
$date = date_now($account->timezone_name);
$offset = date_offset_get($date);
if ($offset != $account->timezone) {
$account->timezone = $offset;
db_query("UPDATE {users} SET timezone='%s' WHERE uid = %d", $offset, $account->uid);
}
}
else {
// If the user doesn't already have a timezone name selected,
// default it to the site timezone name and offset.
$timezone = variable_get('date_default_timezone_name', NULL);
if (!empty($timezone)) {
$date = date_now($timezone);
$offset = date_offset_get($date);
db_query("UPDATE {users} SET timezone_name = '%s', timezone='%s' WHERE uid = %d", $timezone, $offset, $account->uid);
}
}
}
}