1 date.inc date_timezone_names($required = FALSE, $refresh = FALSE)

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 FALSE.

Return value

array: An array of timezone names.

File

core/includes/date.inc, line 551
Date API functions.

Code

function date_timezone_names($required = FALSE, $refresh = FALSE) {
  static $zone_names;
  if (empty($zone_names) || $refresh) {
    $cached = cache_get('date_timezone_identifiers_list');
    $zone_names = !empty($cached) ? $cached->data : array();
    if ($refresh || empty($cached) || empty($zone_names)) {
      $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)) {
          $zone_names[$zone] = $zone;
        }
      }

      if (!empty($zone_names)) {
        cache_set('date_timezone_identifiers_list', $zone_names);
      }
    }
    foreach ($zone_names as $zone) {
      $zone_names[$zone] = t('!timezone', array('!timezone' => t($zone)));
    }
  }
  $none = array('' => '');
  return !$required ? $none + $zone_names : $zone_names;
}