timezone column in users table should have 0 by default, otherwize the following problem occurs:
All users who didn't visit their accounts to specify a time zone have NULL in timezone column. This cause format_date() function to work incorrectly in such call:
$output .= form_item(t('Local time'), format_date(date('U'), 'large', '', $user->timezone));
where $user->timezone is a timezone of the specified user. I'm using such call for a custom profile page to display user's local time. When $user->timezone is null format_date uses time zone of the current (active) user instead of 0.
Of course, this can be overcome by the following call:
$output .= form_item(t('Local time'), format_date(date('U'), 'large', '', (empty($user->timezone)) ? 0 : $user->timezone));
but I though it is better to fix it in the Drupal SQL script.
Comments
Comment #1
magico commentedI couldn't find the refered line of code.
Comment #2
magico commentedComment #3
ardas commentedYou didn't understand me. There is no such call in the code. This is an example of format_date() usage. The problem is in the database - time zone column is NULL without DEFAULT clause which is bad. I just suggest to set DEFAULT 0 for this column to avoid the problem I described.
Thanks.
Comment #4
magico commentedComment #5
ardas commentedThank you for reanimating this issue.
The only fix required is a little change in database script to add DEFAULT 0 for timezone column to prevent the situation when a new user didn't set up his timezone and NULL is in his timezone field which is treated as a time zone of logged in user which is wrong.
Thanks.
Comment #6
magico commentedThe column still has default NULL in 5.x-dev
Anyone accepts this patch?
Comment #7
magico commentedForget the previous patch. This is now correct!
Comment #8
morbus iffA database change like this needs a matching system_update_#### for upgraders.
Comment #9
ardas commentedThis is exactly what I was talking about. Thank you guys for supporting this suggestion.
Comment #10
magico commentedHope this is now correct.
Comment #11
ardas commentedYeah, it looks so.
Comment #12
dmitrig01 commentedNew features go into 6.x-dev
Comment #13
stevenpatzComment #14
ChrisKennedy commentedThe system_update number should be in the 2000 block.
As long as we're fixing this, shouldn't we also update the user table and set timezone to 0 if it's NULL?
Comment #15
panchoI rerolled the patch using Schema API and adding the missing 'not null' property. Also I added updating the user table as suggested by Chris.
I'm not really sure about the consequences though. What if the system-wide default timezone differs from 0? A user timezone of 0 would mean a deviance from default rather than default then...
Comment #16
dpearcefl commentedDoes this still need to be fixed in current d6?