f1cecf03e49d80cf1f2e22ad5831116922f3905d
[jalviewjs.git] / site / swingjs / j2s / java / util / TimeZone.js
1 Clazz.declarePackage ("java.util");
2 Clazz.load (null, "java.util.TimeZone", ["java.lang.InternalError", "$.NullPointerException", "java.util.Date", "$.HashMap"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.ID = "GMT";
5 Clazz.instantialize (this, arguments);
6 }, java.util, "TimeZone", null, Cloneable);
7 Clazz.makeConstructor (c$, 
8 function () {
9 });
10 Clazz.defineMethod (c$, "getOffset", 
11 function (date) {
12 if (this.inDaylightTime ( new java.util.Date (date))) {
13 return this.getRawOffset () + this.getDSTSavings ();
14 }return this.getRawOffset ();
15 }, "~N");
16 Clazz.defineMethod (c$, "getOffsets", 
17 function (date, offsets) {
18 var rawoffset = this.getRawOffset ();
19 var dstoffset = 0;
20 if (this.inDaylightTime ( new java.util.Date (date))) {
21 dstoffset = this.getDSTSavings ();
22 }if (offsets != null) {
23 offsets[0] = rawoffset;
24 offsets[1] = dstoffset;
25 }return rawoffset + dstoffset;
26 }, "~N,~A");
27 Clazz.defineMethod (c$, "getID", 
28 function () {
29 return this.ID;
30 });
31 Clazz.defineMethod (c$, "setID", 
32 function (ID) {
33 if (ID == null) {
34 throw  new NullPointerException ();
35 }this.ID = ID;
36 }, "~S");
37 Clazz.defineMethod (c$, "getDSTSavings", 
38 function () {
39 if (this.useDaylightTime ()) {
40 return 3600000;
41 }return 0;
42 });
43 c$.getTimeZone = Clazz.defineMethod (c$, "getTimeZone", 
44 function (ID) {
45 return java.util.TimeZone.getTimeZone (ID, true);
46 }, "~S");
47 c$.getTimeZone = Clazz.defineMethod (c$, "getTimeZone", 
48  function (ID, fallback) {
49 var tz = null;
50 tz = java.util.TimeZone.parseCustomTimeZone (ID);
51 if (tz == null && fallback) {
52 tz =  new jssun.util.calendar.ZoneInfo ("GMT", 0);
53 }return tz;
54 }, "~S,~B");
55 c$.getAvailableIDs = Clazz.defineMethod (c$, "getAvailableIDs", 
56 function (rawOffset) {
57 return null;
58 }, "~N");
59 c$.getAvailableIDs = Clazz.defineMethod (c$, "getAvailableIDs", 
60 function () {
61 return null;
62 });
63 c$.getDefault = Clazz.defineMethod (c$, "getDefault", 
64 function () {
65 return java.util.TimeZone.getDefaultRef ().clone ();
66 });
67 c$.getDefaultRef = Clazz.defineMethod (c$, "getDefaultRef", 
68 function () {
69 if (java.util.TimeZone.defaultTimeZone == null) {
70 var ms = java.util.TimeZone.getTimeZoneOffsetMillis ();
71 var gmtOffsetID = java.util.TimeZone.getGMTID (ms);
72 java.util.TimeZone.defaultTimeZone = java.util.TimeZone.getTimeZone (gmtOffsetID, true);
73 java.util.TimeZone.addToCache (gmtOffsetID,  new jssun.util.calendar.ZoneInfo (gmtOffsetID, ms));
74 }return java.util.TimeZone.defaultTimeZone;
75 });
76 c$.getTimeZoneOffsetMillis = Clazz.defineMethod (c$, "getTimeZoneOffsetMillis", 
77  function () {
78 {
79 return -(new Date()).getTimezoneOffset() * 60000;
80 }});
81 c$.setDefault = Clazz.defineMethod (c$, "setDefault", 
82 function (zone) {
83 }, "java.util.TimeZone");
84 Clazz.defineMethod (c$, "hasSameRules", 
85 function (other) {
86 return other != null && this.getRawOffset () == other.getRawOffset () && this.useDaylightTime () == other.useDaylightTime ();
87 }, "java.util.TimeZone");
88 Clazz.defineMethod (c$, "clone", 
89 function () {
90 try {
91 var other = Clazz.superCall (this, java.util.TimeZone, "clone", []);
92 other.ID = this.ID;
93 return other;
94 } catch (e) {
95 if (Clazz.exceptionOf (e, CloneNotSupportedException)) {
96 throw  new InternalError ();
97 } else {
98 throw e;
99 }
100 }
101 });
102 c$.parseCustomTimeZone = Clazz.defineMethod (c$, "parseCustomTimeZone", 
103  function (id) {
104 if ((id.length) < (5) || id.indexOf ("GMT") != 0) {
105 return null;
106 }var zi;
107 var neghrmin = java.util.TimeZone.getOffsetHHMM (id);
108 if (neghrmin == null) return null;
109 var gmtOffset = (neghrmin[0]) * (neghrmin[1] * 60 + neghrmin[2]) * 60 * 1000;
110 var gmtID = java.util.TimeZone.getGMTID (gmtOffset);
111 zi =  new jssun.util.calendar.ZoneInfo ();
112 if (gmtOffset == 0) {
113 } else {
114 zi.setRawOffsetReally (gmtOffset);
115 }zi.setID (gmtID);
116 return zi;
117 }, "~S");
118 c$.getOffsetHHMM = Clazz.defineMethod (c$, "getOffsetHHMM", 
119  function (id) {
120 var index = 3;
121 var length = id.length;
122 var negative = false;
123 var c = id.charAt (index++);
124 if (c == '-') {
125 negative = true;
126 } else if (c != '+') {
127 return null;
128 }var hours = 0;
129 var num = 0;
130 var countDelim = 0;
131 var len = 0;
132 while (index < length) {
133 c = id.charAt (index++);
134 if (c == ':') {
135 if (countDelim > 0) {
136 return null;
137 }if (len > 2) {
138 return null;
139 }hours = num;
140 countDelim++;
141 num = 0;
142 len = 0;
143 continue;
144 }if (c < '0' || c > '9') {
145 return null;
146 }num = num * 10 + (c.charCodeAt (0) - 48);
147 len++;
148 }
149 if (index != length) {
150 return null;
151 }if (countDelim == 0) {
152 if (len <= 2) {
153 hours = num;
154 num = 0;
155 } else {
156 hours = Clazz.doubleToInt (num / 100);
157 num %= 100;
158 }} else {
159 if (len != 2) {
160 return null;
161 }}if (hours > 23 || num > 59) {
162 return null;
163 }return  Clazz.newIntArray (-1, [(negative ? -1 : 1), hours, num]);
164 }, "~S");
165 c$.getGMTID = Clazz.defineMethod (c$, "getGMTID", 
166  function (gmtOffset) {
167 var isNegative = (gmtOffset < 0);
168 if (isNegative) gmtOffset = -gmtOffset;
169 gmtOffset = Clazz.doubleToInt (gmtOffset / 60000);
170 var hours = Clazz.doubleToInt (gmtOffset / 60);
171 var min = gmtOffset - hours * 60;
172 var NN = "00" + hours;
173 NN = NN.substring (NN.length - 2);
174 var MM = "00" + min;
175 MM = MM.substring (MM.length - 2);
176 return "GMT" + (isNegative ? "-" : "") + NN;
177 }, "~N");
178 c$.getCustomTimeZone = Clazz.defineMethod (c$, "getCustomTimeZone", 
179 function (originalId, gmtOffset) {
180 var id = java.util.TimeZone.toCustomID (gmtOffset);
181 var zi = java.util.TimeZone.getFromCache (id);
182 if (zi == null) {
183 zi =  new jssun.util.calendar.ZoneInfo (id, gmtOffset);
184 zi = java.util.TimeZone.addToCache (id, zi);
185 if (originalId != null && !id.equals (originalId)) {
186 zi = java.util.TimeZone.addToCache (originalId, zi);
187 }}return zi.clone ();
188 }, "~S,~N");
189 c$.toCustomID = Clazz.defineMethod (c$, "toCustomID", 
190 function (gmtOffset) {
191 var sign;
192 var offset = Clazz.doubleToInt (gmtOffset / 60000);
193 if (offset >= 0) {
194 sign = '+';
195 } else {
196 sign = '-';
197 offset = -offset;
198 }var hh = Clazz.doubleToInt (offset / 60);
199 var mm = offset % 60;
200 var buf =  Clazz.newCharArray (-1, ['G', 'M', 'T', sign, '0', '0', ':', '0', '0']);
201 if (hh >= 10) {
202 buf[4] = String.fromCharCode ((buf[4]).charCodeAt (0) + (Clazz.doubleToInt (hh / 10)));
203 }buf[5] = String.fromCharCode ((buf[5]).charCodeAt (0) + (hh % 10));
204 if (mm != 0) {
205 buf[7] = String.fromCharCode ((buf[7]).charCodeAt (0) + (Clazz.doubleToInt (mm / 10)));
206 buf[8] = String.fromCharCode ((buf[8]).charCodeAt (0) + (mm % 10));
207 }return  String.instantialize (buf);
208 }, "~N");
209 c$.getFromCache = Clazz.defineMethod (c$, "getFromCache", 
210 function (id) {
211 if (java.util.TimeZone.zoneInfoObjects == null) {
212 return null;
213 }return java.util.TimeZone.zoneInfoObjects.get (id);
214 }, "~S");
215 c$.addToCache = Clazz.defineMethod (c$, "addToCache", 
216 function (id, zi) {
217 if (java.util.TimeZone.zoneInfoObjects == null) {
218 java.util.TimeZone.zoneInfoObjects =  new java.util.HashMap ();
219 } else {
220 var zone = java.util.TimeZone.zoneInfoObjects.get (id);
221 if (zone != null) {
222 return zone;
223 }}java.util.TimeZone.zoneInfoObjects.put (id, zi);
224 return zi;
225 }, "~S,jssun.util.calendar.ZoneInfo");
226 Clazz.defineStatics (c$,
227 "SHORT", 0,
228 "LONG", 1,
229 "NO_TIMEZONE", null,
230 "defaultTimeZone", null,
231 "GMT_ID", "GMT",
232 "GMT_ID_LENGTH", 3,
233 "zoneInfoObjects", null);
234 });