Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/third_party/closure/goog/locale/timezonelist.js
2868 views
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
23
goog.require('goog.locale');
24
25
26
/**
27
* Returns the displayable list of short timezone names paired with its id for
28
* the current locale, selected based on the region or language provided.
29
*
30
* This method depends on `goog.locale.TimeZone*__<locale>` available
31
* from http://go/js_locale_data. Users of this method must add a dependency on
32
* this.
33
*
34
* @param {string=} opt_regionOrLang If region tag is provided, timezone ids
35
* specific this region are considered. If language is provided, all regions
36
* for which this language is defacto official is considered. If
37
* this parameter is not speficied, current locale is used to
38
* extract this information.
39
*
40
* @return {!Array<Object>} Localized and relevant list of timezone names
41
* and ids.
42
*/
43
goog.locale.getTimeZoneSelectedShortNames = function(opt_regionOrLang) {
44
return goog.locale.getTimeZoneNameList_(
45
'TimeZoneSelectedShortNames', opt_regionOrLang);
46
};
47
48
49
/**
50
* Returns the displayable list of long timezone names paired with its id for
51
* the current locale, selected based on the region or language provided.
52
*
53
* This method depends on `goog.locale.TimeZone*__<locale>` available
54
* from http://go/js_locale_data. Users of this method must add a dependency on
55
* this.
56
*
57
* @param {string=} opt_regionOrLang If region tag is provided, timezone ids
58
* specific this region are considered. If language is provided, all regions
59
* for which this language is defacto official is considered. If
60
* this parameter is not speficied, current locale is used to
61
* extract this information.
62
*
63
* @return {!Array<Object>} Localized and relevant list of timezone names
64
* and ids.
65
*/
66
goog.locale.getTimeZoneSelectedLongNames = function(opt_regionOrLang) {
67
return goog.locale.getTimeZoneNameList_(
68
'TimeZoneSelectedLongNames', opt_regionOrLang);
69
};
70
71
72
/**
73
* Returns the displayable list of long timezone names paired with its id for
74
* the current locale.
75
*
76
* This method depends on `goog.locale.TimeZoneAllLongNames__<locale>` available
77
* from http://go/js_locale_data. Users of this method must add a dependency on
78
* this.
79
*
80
* @return {Array<Object>} localized and relevant list of timezone names
81
* and ids.
82
*/
83
goog.locale.getTimeZoneAllLongNames = function() {
84
var locale = goog.locale.getLocale();
85
return /** @type {Array<Object>} */ (
86
goog.locale.getResource('TimeZoneAllLongNames', locale));
87
};
88
89
90
/**
91
* Returns the displayable list of timezone names paired with its id for
92
* the current locale, selected based on the region or language provided.
93
*
94
* This method depends on `goog.locale.TimeZone*__<locale>` available
95
* from http://go/js_locale_data. Users of this method must add a dependency on
96
* this.
97
*
98
* @param {string} nameType Resource name to be loaded to get the names.
99
*
100
* @param {string=} opt_resource If resource is region tag, timezone ids
101
* specific this region are considered. If it is language, all regions
102
* for which this language is defacto official is considered. If it is
103
* undefined, current locale is used to extract this information.
104
*
105
* @return {!Array<Object>} Localized and relevant list of timezone names
106
* and ids.
107
* @private
108
*/
109
goog.locale.getTimeZoneNameList_ = function(nameType, opt_resource) {
110
var locale = goog.locale.getLocale();
111
112
if (!opt_resource) {
113
opt_resource = goog.locale.getRegionSubTag(locale);
114
}
115
// if there is no region subtag, use the language itself as the resource
116
if (!opt_resource) {
117
opt_resource = locale;
118
}
119
120
var names = goog.locale.getResource(nameType, locale);
121
var ids = goog.locale.getResource('TimeZoneSelectedIds', opt_resource);
122
var len = ids.length;
123
var result = [];
124
125
for (var i = 0; i < len; i++) {
126
var id = ids[i];
127
result.push({'id': id, 'name': names[id]});
128
}
129
return result;
130
};
131
132