You are here

function date_timezone_names in Date 7.2

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

Returns a translated array of timezone names.

Cache the untranslated array, make the translated array a static variable.

Parameters

bool $required: (optional) If FALSE, the returned array will include a blank value. Defaults to FALSE.

bool $refresh: (optional) Whether to refresh the list. Defaults to TRUE.

Return value

array An array of timezone names.

3 calls to date_timezone_names()
date_devel_generate in ./date.devel_generate.inc
Implements hook_devel_generate().
date_timezone_element_process in date_api/date_api_elements.inc
Creates a timezone form element.
date_timezone_is_valid in date_api/date_api.module
Determines if a timezone string is valid.

File

date_api/date_api.module, line 1710
This module will make the date API available to other modules.

Code

function date_timezone_names($required = FALSE, $refresh = FALSE) {
  static $zonenames;
  if (empty($zonenames) || $refresh) {
    $cached = cache_get('date_timezone_identifiers_list');
    $zonenames = !empty($cached) ? $cached->data : array();
    if ($refresh || empty($cached) || empty($zonenames)) {
      $data = timezone_identifiers_list();
      asort($data);
      foreach ($data as $delta => $zone) {

        // Because many timezones 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 (!empty($zonenames)) {
        cache_set('date_timezone_identifiers_list', $zonenames);
      }
    }
    foreach ($zonenames as $zone) {
      $zonenames[$zone] = t('!timezone', array(
        '!timezone' => t($zone),
      ));
    }
  }
  $none = array(
    '' => '',
  );
  return !$required ? $none + $zonenames : $zonenames;
}