Debian Codegraph @

closure-library/closure/goog/locale/timezonelist.js

raw
1 // Copyright 2007 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 /**
16 * @fileoverview Functions for listing timezone names.
17 * @suppress {deprecated} Use goog.i18n instead.
18 */
19
20 /** @suppress {extraProvide} */
21 goog.provide('goog.locale.TimeZoneList');
22 goog.provide('goog.locale.getTimeZoneAllLongNames');
23 goog.provide('goog.locale.getTimeZoneSelectedLongNames');
24 goog.provide('goog.locale.getTimeZoneSelectedShortNames');
25
26 goog.require('goog.locale');
27
28
29 /**
30 * Returns the displayable list of short timezone names paired with its id for
31 * the current locale, selected based on the region or language provided.
32 *
33 * This method depends on `goog.locale.TimeZone*__<locale>` available
34 * from http://go/js_locale_data. Users of this method must add a dependency on
35 * this.
36 *
37 * @param {string=} opt_regionOrLang If region tag is provided, timezone ids
38 * specific this region are considered. If language is provided, all regions
39 * for which this language is defacto official is considered. If
40 * this parameter is not speficied, current locale is used to
41 * extract this information.
42 *
43 * @return {!Array<Object>} Localized and relevant list of timezone names
44 * and ids.
45 */
46 goog.locale.getTimeZoneSelectedShortNames = function(opt_regionOrLang) {
47 return goog.locale.getTimeZoneNameList_(
48 'TimeZoneSelectedShortNames', opt_regionOrLang);
49 };
50
51
52 /**
53 * Returns the displayable list of long timezone names paired with its id for
54 * the current locale, selected based on the region or language provided.
55 *
56 * This method depends on `goog.locale.TimeZone*__<locale>` available
57 * from http://go/js_locale_data. Users of this method must add a dependency on
58 * this.
59 *
60 * @param {string=} opt_regionOrLang If region tag is provided, timezone ids
61 * specific this region are considered. If language is provided, all regions
62 * for which this language is defacto official is considered. If
63 * this parameter is not speficied, current locale is used to
64 * extract this information.
65 *
66 * @return {!Array<Object>} Localized and relevant list of timezone names
67 * and ids.
68 */
69 goog.locale.getTimeZoneSelectedLongNames = function(opt_regionOrLang) {
70 return goog.locale.getTimeZoneNameList_(
71 'TimeZoneSelectedLongNames', opt_regionOrLang);
72 };
73
74
75 /**
76 * Returns the displayable list of long timezone names paired with its id for
77 * the current locale.
78 *
79 * This method depends on `goog.locale.TimeZoneAllLongNames__<locale>` available
80 * from http://go/js_locale_data. Users of this method must add a dependency on
81 * this.
82 *
83 * @return {Array<Object>} localized and relevant list of timezone names
84 * and ids.
85 */
86 goog.locale.getTimeZoneAllLongNames = function() {
87 var locale = goog.locale.getLocale();
88 return /** @type {Array<Object>} */ (
89 goog.locale.getResource('TimeZoneAllLongNames', locale));
90 };
91
92
93 /**
94 * Returns the displayable list of timezone names paired with its id for
95 * the current locale, selected based on the region or language provided.
96 *
97 * This method depends on `goog.locale.TimeZone*__<locale>` available
98 * from http://go/js_locale_data. Users of this method must add a dependency on
99 * this.
100 *
101 * @param {string} nameType Resource name to be loaded to get the names.
102 *
103 * @param {string=} opt_resource If resource is region tag, timezone ids
104 * specific this region are considered. If it is language, all regions
105 * for which this language is defacto official is considered. If it is
106 * undefined, current locale is used to extract this information.
107 *
108 * @return {!Array<Object>} Localized and relevant list of timezone names
109 * and ids.
110 * @private
111 */
112 goog.locale.getTimeZoneNameList_ = function(nameType, opt_resource) {
113 var locale = goog.locale.getLocale();
114
115 if (!opt_resource) {
116 opt_resource = goog.locale.getRegionSubTag(locale);
117 }
118 // if there is no region subtag, use the language itself as the resource
119 if (!opt_resource) {
120 opt_resource = locale;
121 }
122
123 var names = goog.locale.getResource(nameType, locale);
124 var ids = goog.locale.getResource('TimeZoneSelectedIds', opt_resource);
125 var len = ids.length;
126 var result = [];
127
128 for (var i = 0; i < len; i++) {
129 var id = ids[i];
130 result.push({'id': id, 'name': names[id]});
131 }
132 return result;
133 };