-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
74 lines (63 loc) · 1.77 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var jstz = require('jstz')
module.exports = function inUS() {
return isInUSTimezone() || isUSLocale()
}
var countryCodes = {
US: 'United States'
}
module.exports.isInUSTimezone = isInUSTimezone
module.exports.isUSLocale = isUSLocale
function isUSLocale() {
var locale = browserLocale()
var code = locale
if (locale.indexOf('-') >= 0) {
code = locale.split('-')[1]
}
return !!countryCodes[code.toUpperCase()]
}
var timezoneCities = {
'America/Adak': true,
'America/Anchorage': true,
'America/Boise': true,
'America/Chicago': true,
'America/Dawson': true,
'America/Denver': true,
'America/Detroit': true,
'America/Los_Angeles': true,
'America/Indiana/Indianapolis': true,
'America/Indiana/Knox': true,
'America/Indiana/Marengo': true,
'America/Indiana/Petersburg': true,
'America/Indiana/Tell_City': true,
'America/Indiana/Vevay': true,
'America/Indiana/Vincennes': true,
'America/Indiana/Winamec': true,
'America/Kentucky/Louisville': true,
'America/Kentucky/Menticello': true,
'America/Menominee': true,
'America/Yakutat': true,
'America/Honolulu': true,
'America/New_York': true,
'America/Nome': true,
'America/North_Dakota/Beulah': true,
'America/North_Dakota/Center': true,
'America/North_Dakota/New_Salem': true,
'America/Guam': true,
'America/Puerto_Rico': true,
'America/Phoenix': true
}
function isInUSTimezone() {
var tz = jstz.determine().name()
return Boolean(tz && timezoneCities[tz])
}
function browserLocale() {
if (window.navigator.languages && window.navigator.languages.length > 0) {
// Latest versions of Chrome and Firefox set this correctly
return navigator.languages[0]
}
if (navigator.userLanguage) {
// IE only
return navigator.userLanguage
}
return navigator.language
}