according to the documentation there is no timezone property for anonymous user

function drupal_anonymous_user() {
  $user = variable_get('drupal_anonymous_user_object', new stdClass);
  $user->uid = 0;
  $user->hostname = ip_address();
  $user->roles = array();
  $user->roles[DRUPAL_ANONYMOUS_RID] = 'anonymous user';
  $user->cache = 0;
  return $user;
}

I want to know the way to follow for adding this feature.

Thank you

Comments

jordanmagnuson’s picture

Currently this module does not support setting a timezone for anonymous users.

It should be possible, though, to use the timezone detect library to grab the anonymous user's timezone, and then save it in the global $_SESSION variable, e.g. as $_SESSION[‘timezone’].

See https://drupal.org/node/1985906 .

jordanmagnuson’s picture

Status: Active » Closed (works as designed)
sanjay.maharjan’s picture

Is this problem solved?? I want to show the time of my event to anonymous user according to his/her local time. How can I achieve such functionality?

jordanmagnuson’s picture

See #1: There is no "built in" functionality for this in the module. It should be possible, though, to use the timezone detect library to grab the anonymous user's timezone, and then save it in the global $_SESSION variable, e.g. as $_SESSION[‘timezone’].

ivanbueno’s picture

StatusFileSize
new3.08 KB

I, too, need this feature...

Attached is a patch that implements #1. However, $_SESSION['timezone'] is no longer used by Drupal 7.x. (It was used in Drupal 5.)

There is no way to override anon's timezone without hacking core.

In drupal_session_initialize(), the timezone is set using:
date_default_timezone_set(drupal_get_user_timezone());

And drupal_get_user_timezone() does not allow any alterations:

function drupal_get_user_timezone() {
  global $user;
  if (variable_get('configurable_timezones', 1) && $user->uid && $user->timezone) {
    return $user->timezone;
  }
  else {
    // Ignore PHP strict notice if time zone has not yet been set in the php.ini
    // configuration.
    return variable_get('date_default_timezone', @date_default_timezone_get());
  }
}

Let me know if I'm missing anything.

Anonymous’s picture

Assigned: Sel_Space » Unassigned
Status: Closed (works as designed) » Needs review

Status: Needs review » Needs work

The last submitted patch, 5: timezone-detect-for-anon-2174891-5.patch, failed testing. View results

jordanmagnuson’s picture

Status: Needs work » Closed (won't fix)

Won't fix this, since it seems to require a core hack. Those who need the functionality can hack core as required, or petition for the required core code changes.