forked from Gutza/Converter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconverter_tz.js
102 lines (92 loc) · 2 KB
/
converter_tz.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
"use strict";
MCE.tzUtil = {
tzLegitRegexp: '',
timezones : {
"IDLW":-12,
"NT":-11,
"HST":-10,
"AKST":-9,
"PST":-8,"AKDT":-8,
"MST":-7,"PDT":-7,
"CST":-6,"MDT":-6,
"EST":-5,"CDT":-5,
"EDT":-4,"AST":-4,
"GUY":-3,"ADT":-3,
"AT":-2,
"UTC":0,"GMT":0,"Z":0,"WET":0,
"WEST":1,"CET":1,"BST":1,"IST":1,
"CEST":2,"EET":2,
"EEST":3,"MSK":3,
"MSD":4,"ZP4":4,
"ZP5":5,
"ZP6":6,
"WAST":7,
"AWST":8,"WST":8,
"JST":9,
"ACST":9.5,
"ACDT":10.5,
"AEST":10,
"AEDT":11,
"NZST":12,"IDLE":12,
"NZDT":13
},
// returns an offset in hours
get_local_offset()
{
var D=new Date();
return -D.getTimezoneOffset()/60;
},
// tz is a timezone of the form +/-xxxx or DST, CET, GMT, etc
// returns an offset in hours
get_tz_offset(tz)
{
// Is it +xxxx or -xxxx?
/*
Note: tightened from /^([+-])([0-9]{2})([0-9]{2})$/
to /^([+-])(0[0-9]|1[0-2])([03]0)$/
because we want to reduce false positives on innocent
ranges such as "1000-1024".
We can afford doing that because there are no legitimate
timezones fractioned below half hours.
*/
var re = /^([+-])(0[0-9]|1[0-2])([03]0)$/;
var ree=re.exec(tz);
if (ree && ree[0]) {
var sgn=new Number(ree[1]+'1');
if (ree[2].substr(0,0)=='0') {
ree[2]=ree[2].substr(1);
}
var h=new Number(ree[2]);
var m=new Number(ree[3]);
return sgn*(h+m/60);
}
if (tz in this.timezones) {
return this.timezones[tz];
}
return undefined;
},
validate_hour(hour)
{
if (hour===undefined || hour==='' || hour>23) {
return false;
}
return true;
},
validate_minute(minutes)
{
if (minutes===undefined || minutes==='' || minutes>59) {
return false;
}
return true;
},
init()
{
var tzLegit=new Array();
var tzTmp;
for(tzTmp in MCE.tzUtil.timezones) {
tzLegit.push(tzTmp);
}
MCE.tzUtil.tzLegitRegexp=tzLegit.join('|');
}
};
MCE.tzUtil.init();