You are here

function date_timezone_update_site in Date 5.2

Same name and namespace in other branches
  1. 6.2 date_timezone/date_timezone.module \date_timezone_update_site()
  2. 6 date_timezone/date_timezone.module \date_timezone_update_site()

Callback from site timezone settings form to update site timezone info. When the timezone name is updated, update the offset as well.

File

date_timezone/date_timezone.module, line 117
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_update_site($element) {
  $timezone = $element['#value'];
  if (empty($timezone)) {
    $offset = $element['#offset'];
  }
  else {
    variable_set('date_default_timezone_name', $timezone);
    $date = date_now($timezone);
    $offset = date_offset_get($date);
  }

  // We overrode the event module's form handling, give it back
  // the values it expected to find in its submission handler.
  if (module_exists('event') && db_table_exists('event_timezones')) {
    $event_zone = date_event_zonelist_by_name(str_replace('_', ' ', $timezone));

    // The Event module will set its own variable.
    if (!empty($event_zone['timezone'])) {
      form_set_value($element, $event_zone['timezone'] . '|' . $offset);
    }
    else {
      form_set_value($element, $offset);
    }
  }
  else {
    form_set_value($element, $offset);
  }
}