You are here

function date_timezone_names in Date 5.2

Same name and namespace in other branches
  1. 6.2 date_api.module \date_timezone_names()
  2. 6 date_api.module \date_timezone_names()
  3. 7.3 date_api/date_api.module \date_timezone_names()
  4. 7 date_api/date_api.module \date_timezone_names()
  5. 7.2 date_api/date_api.module \date_timezone_names()

A translated array of timezone names. Cache the untranslated array, make the translated array a static variable.

Parameters

$required: If not required, returned array will include a blank value.

Return value

an array of timezone names

5 calls to date_timezone_names()
date_generate in date/date_content_generate.inc
date_timezone_is_valid in ./date_api.module
date_timezone_process in ./date_api_elements.inc
Create a timezone form element.
date_timezone_site_form in date_timezone/date_timezone.module
Override form for the site timezone settings form. Display a list of timezone names instead of offsets and hide the offset value.
date_timezone_user_form in date_timezone/date_timezone.module
Override form for the user timezone settings form. Display a list of timezone names instead of offsets and hide the offset value.

File

./date_api.module, line 450
This module will make the date API available to other modules. Designed to provide a light but flexible assortment of functions and constants, with more functionality in additional files that are not loaded unless other modules specifically include them.

Code

function date_timezone_names($required = FALSE, $refresh = FALSE) {
  static $zonenames;
  if (empty($zonenames) || $refresh) {
    $cached = cache_get('date_timezone_identifiers_list', 'cache');
    $zonenames = unserialize($cached->data);
    if ($refresh || empty($cached) || empty($zonenames)) {
      $data = timezone_identifiers_list();

      // Use include instead of include once in case the function gets
      // refreshed via devel or other API and is called more than once.
      if (module_exists('date_php4')) {
        include './' . drupal_get_path('module', 'date_php4') . '/date_php4_missing_data.inc';
      }
      foreach ($data as $delta => $zone) {

        // Because many time zones exist in PHP only for backward
        // compatibility reasons and should not be used, the list is
        // filtered by a regular expression.
        if (preg_match('!^((Africa|America|Antarctica|Arctic|Asia|Atlantic|Australia|Europe|Indian|Pacific)/|UTC$)!', $zone)) {
          $zonenames[$zone] = $zone;
        }
      }

      // If using PHP4, filter the list down to only the timezones
      // the PHP4 wrapper has data for.
      if (module_exists('date_php4')) {
        foreach ($missing_timezone_data as $zone) {
          unset($zonenames[$zone]);
        }
      }

      // If using Event, further filter the list down to only
      // zones that exist in the event module.
      if (module_exists('event') && db_table_exists('event_timezones')) {
        $result = db_query("SELECT name FROM {event_timezones} ORDER BY name");
        $names = array();
        while ($row = db_fetch_array($result)) {
          $names[] = str_replace(' ', '_', $row['name']);
        }
        foreach ($zonenames as $name => $zone) {
          if (!in_array($name, $names)) {
            unset($zonenames[$name]);
          }
        }
      }
      if (!empty($zonenames)) {
        cache_set('date_timezone_identifiers_list', 'cache', serialize($zonenames));
      }
    }
    else {
      foreach ($zonenames as $zone) {
        $zonenames[$zone] = t('!timezone', array(
          '!timezone' => $zone,
        ));
      }
    }
  }
  $none = array(
    '' => '',
  );
  return !$required ? $none + $zonenames : $zonenames;
}