Path: blob/trunk/third_party/closure/goog/locale/timezonelist.js
2868 views
// Copyright 2007 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview Functions for listing timezone names.16* @suppress {deprecated} Use goog.i18n instead.17*/1819/** @suppress {extraProvide} */20goog.provide('goog.locale.TimeZoneList');2122goog.require('goog.locale');232425/**26* Returns the displayable list of short timezone names paired with its id for27* the current locale, selected based on the region or language provided.28*29* This method depends on `goog.locale.TimeZone*__<locale>` available30* from http://go/js_locale_data. Users of this method must add a dependency on31* this.32*33* @param {string=} opt_regionOrLang If region tag is provided, timezone ids34* specific this region are considered. If language is provided, all regions35* for which this language is defacto official is considered. If36* this parameter is not speficied, current locale is used to37* extract this information.38*39* @return {!Array<Object>} Localized and relevant list of timezone names40* and ids.41*/42goog.locale.getTimeZoneSelectedShortNames = function(opt_regionOrLang) {43return goog.locale.getTimeZoneNameList_(44'TimeZoneSelectedShortNames', opt_regionOrLang);45};464748/**49* Returns the displayable list of long timezone names paired with its id for50* the current locale, selected based on the region or language provided.51*52* This method depends on `goog.locale.TimeZone*__<locale>` available53* from http://go/js_locale_data. Users of this method must add a dependency on54* this.55*56* @param {string=} opt_regionOrLang If region tag is provided, timezone ids57* specific this region are considered. If language is provided, all regions58* for which this language is defacto official is considered. If59* this parameter is not speficied, current locale is used to60* extract this information.61*62* @return {!Array<Object>} Localized and relevant list of timezone names63* and ids.64*/65goog.locale.getTimeZoneSelectedLongNames = function(opt_regionOrLang) {66return goog.locale.getTimeZoneNameList_(67'TimeZoneSelectedLongNames', opt_regionOrLang);68};697071/**72* Returns the displayable list of long timezone names paired with its id for73* the current locale.74*75* This method depends on `goog.locale.TimeZoneAllLongNames__<locale>` available76* from http://go/js_locale_data. Users of this method must add a dependency on77* this.78*79* @return {Array<Object>} localized and relevant list of timezone names80* and ids.81*/82goog.locale.getTimeZoneAllLongNames = function() {83var locale = goog.locale.getLocale();84return /** @type {Array<Object>} */ (85goog.locale.getResource('TimeZoneAllLongNames', locale));86};878889/**90* Returns the displayable list of timezone names paired with its id for91* the current locale, selected based on the region or language provided.92*93* This method depends on `goog.locale.TimeZone*__<locale>` available94* from http://go/js_locale_data. Users of this method must add a dependency on95* this.96*97* @param {string} nameType Resource name to be loaded to get the names.98*99* @param {string=} opt_resource If resource is region tag, timezone ids100* specific this region are considered. If it is language, all regions101* for which this language is defacto official is considered. If it is102* undefined, current locale is used to extract this information.103*104* @return {!Array<Object>} Localized and relevant list of timezone names105* and ids.106* @private107*/108goog.locale.getTimeZoneNameList_ = function(nameType, opt_resource) {109var locale = goog.locale.getLocale();110111if (!opt_resource) {112opt_resource = goog.locale.getRegionSubTag(locale);113}114// if there is no region subtag, use the language itself as the resource115if (!opt_resource) {116opt_resource = locale;117}118119var names = goog.locale.getResource(nameType, locale);120var ids = goog.locale.getResource('TimeZoneSelectedIds', opt_resource);121var len = ids.length;122var result = [];123124for (var i = 0; i < len; i++) {125var id = ids[i];126result.push({'id': id, 'name': names[id]});127}128return result;129};130131132