d583abceb46f223a631cb9527258832658f6b8bb
[jalviewjs.git] / site / swingjs / j2s / java / util / SimpleTimeZone.js
1 Clazz.declarePackage ("java.util");
2 Clazz.load (["java.util.TimeZone", "jssun.util.calendar.CalendarSystem", "$.Gregorian"], "java.util.SimpleTimeZone", ["java.lang.IllegalArgumentException", "jssun.util.calendar.CalendarUtils"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.startMonth = 0;
5 this.startDay = 0;
6 this.startDayOfWeek = 0;
7 this.startTime = 0;
8 this.startTimeMode = 0;
9 this.endMonth = 0;
10 this.endDay = 0;
11 this.endDayOfWeek = 0;
12 this.endTime = 0;
13 this.endTimeMode = 0;
14 this.startYear = 0;
15 this.rawOffset = 0;
16 this.useDaylight = false;
17 this.monthLength = null;
18 this.startMode = 0;
19 this.endMode = 0;
20 this.dstSavings = 0;
21 this.cacheYear = 0;
22 this.cacheStart = 0;
23 this.cacheEnd = 0;
24 this.serialVersionOnStream = 2;
25 Clazz.instantialize (this, arguments);
26 }, java.util, "SimpleTimeZone", java.util.TimeZone);
27 Clazz.prepareFields (c$, function () {
28 this.monthLength = java.util.SimpleTimeZone.staticMonthLength;
29 });
30 Clazz.makeConstructor (c$, 
31 function (rawOffset, ID) {
32 Clazz.superConstructor (this, java.util.SimpleTimeZone, []);
33 this.rawOffset = rawOffset;
34 this.setID (ID);
35 this.dstSavings = 3600000;
36 }, "~N,~S");
37 Clazz.makeConstructor (c$, 
38 function (rawOffset, ID, startMonth, startDay, startDayOfWeek, startTime, endMonth, endDay, endDayOfWeek, endTime) {
39 this.construct (rawOffset, ID, startMonth, startDay, startDayOfWeek, startTime, 0, endMonth, endDay, endDayOfWeek, endTime, 0, 3600000);
40 }, "~N,~S,~N,~N,~N,~N,~N,~N,~N,~N");
41 Clazz.makeConstructor (c$, 
42 function (rawOffset, ID, startMonth, startDay, startDayOfWeek, startTime, endMonth, endDay, endDayOfWeek, endTime, dstSavings) {
43 this.construct (rawOffset, ID, startMonth, startDay, startDayOfWeek, startTime, 0, endMonth, endDay, endDayOfWeek, endTime, 0, dstSavings);
44 }, "~N,~S,~N,~N,~N,~N,~N,~N,~N,~N,~N");
45 Clazz.makeConstructor (c$, 
46 function (rawOffset, ID, startMonth, startDay, startDayOfWeek, startTime, startTimeMode, endMonth, endDay, endDayOfWeek, endTime, endTimeMode, dstSavings) {
47 Clazz.superConstructor (this, java.util.SimpleTimeZone, []);
48 this.setID (ID);
49 this.rawOffset = rawOffset;
50 this.startMonth = startMonth;
51 this.startDay = startDay;
52 this.startDayOfWeek = startDayOfWeek;
53 this.startTime = startTime;
54 this.startTimeMode = startTimeMode;
55 this.endMonth = endMonth;
56 this.endDay = endDay;
57 this.endDayOfWeek = endDayOfWeek;
58 this.endTime = endTime;
59 this.endTimeMode = endTimeMode;
60 this.dstSavings = dstSavings;
61 this.decodeRules ();
62 if (dstSavings <= 0) {
63 throw  new IllegalArgumentException ("Illegal daylight saving value: " + dstSavings);
64 }}, "~N,~S,~N,~N,~N,~N,~N,~N,~N,~N,~N,~N,~N");
65 Clazz.defineMethod (c$, "setStartYear", 
66 function (year) {
67 this.startYear = year;
68 this.invalidateCache ();
69 }, "~N");
70 Clazz.defineMethod (c$, "setStartRule", 
71 function (startMonth, startDay, startDayOfWeek, startTime) {
72 this.startMonth = startMonth;
73 this.startDay = startDay;
74 this.startDayOfWeek = startDayOfWeek;
75 this.startTime = startTime;
76 this.startTimeMode = 0;
77 this.decodeStartRule ();
78 this.invalidateCache ();
79 }, "~N,~N,~N,~N");
80 Clazz.defineMethod (c$, "setStartRule", 
81 function (startMonth, startDay, startTime) {
82 this.setStartRule (startMonth, startDay, 0, startTime);
83 }, "~N,~N,~N");
84 Clazz.defineMethod (c$, "setStartRule", 
85 function (startMonth, startDay, startDayOfWeek, startTime, after) {
86 if (after) {
87 this.setStartRule (startMonth, startDay, -startDayOfWeek, startTime);
88 } else {
89 this.setStartRule (startMonth, -startDay, -startDayOfWeek, startTime);
90 }}, "~N,~N,~N,~N,~B");
91 Clazz.defineMethod (c$, "setEndRule", 
92 function (endMonth, endDay, endDayOfWeek, endTime) {
93 this.endMonth = endMonth;
94 this.endDay = endDay;
95 this.endDayOfWeek = endDayOfWeek;
96 this.endTime = endTime;
97 this.endTimeMode = 0;
98 this.decodeEndRule ();
99 this.invalidateCache ();
100 }, "~N,~N,~N,~N");
101 Clazz.defineMethod (c$, "setEndRule", 
102 function (endMonth, endDay, endTime) {
103 this.setEndRule (endMonth, endDay, 0, endTime);
104 }, "~N,~N,~N");
105 Clazz.defineMethod (c$, "setEndRule", 
106 function (endMonth, endDay, endDayOfWeek, endTime, after) {
107 if (after) {
108 this.setEndRule (endMonth, endDay, -endDayOfWeek, endTime);
109 } else {
110 this.setEndRule (endMonth, -endDay, -endDayOfWeek, endTime);
111 }}, "~N,~N,~N,~N,~B");
112 Clazz.defineMethod (c$, "getOffset", 
113 function (date) {
114 return this.getOffsets (date, null);
115 }, "~N");
116 Clazz.overrideMethod (c$, "getOffsets", 
117 function (date, offsets) {
118 var offset = this.rawOffset;
119 computeOffset : if (this.useDaylight) {
120 {
121 if (this.cacheStart != 0) {
122 if (date >= this.cacheStart && date < this.cacheEnd) {
123 offset += this.dstSavings;
124 break computeOffset;
125 }}}var cal = date >= -12219292800000 ? java.util.SimpleTimeZone.gcal : jssun.util.calendar.CalendarSystem.forName ("julian");
126 var cdate = cal.newCalendarDate (java.util.TimeZone.NO_TIMEZONE);
127 cal.getCalendarDate (date + this.rawOffset, cdate);
128 var year = cdate.getNormalizedYear ();
129 if (year >= this.startYear) {
130 cdate.setTimeOfDay (0, 0, 0, 0);
131 offset = this.getOffset (cal, cdate, year, date);
132 }}if (offsets != null) {
133 offsets[0] = this.rawOffset;
134 offsets[1] = offset - this.rawOffset;
135 }return offset;
136 }, "~N,~A");
137 Clazz.defineMethod (c$, "getOffset", 
138 function (era, year, month, day, dayOfWeek, millis) {
139 if (era != 1 && era != 0) {
140 throw  new IllegalArgumentException ("Illegal era " + era);
141 }var y = year;
142 if (era == 0) {
143 y = 1 - y;
144 }if (y >= 292278994) {
145 y = 2800 + y % 2800;
146 } else if (y <= -292269054) {
147 y = jssun.util.calendar.CalendarUtils.mod (y, 28);
148 }var m = month + 1;
149 var cal = java.util.SimpleTimeZone.gcal;
150 var cdate = cal.newCalendarDate (java.util.TimeZone.NO_TIMEZONE);
151 cdate.setDate (y, m, day);
152 var time = cal.getTime (cdate);
153 time += millis - this.rawOffset;
154 if (time < -12219292800000) {
155 cal = jssun.util.calendar.CalendarSystem.forName ("julian");
156 cdate = cal.newCalendarDate (java.util.TimeZone.NO_TIMEZONE);
157 cdate.setNormalizedDate (y, m, day);
158 time = cal.getTime (cdate) + millis - this.rawOffset;
159 }if ((cdate.getNormalizedYear () != y) || (cdate.getMonth () != m) || (cdate.getDayOfMonth () != day) || (dayOfWeek < 1 || dayOfWeek > 7) || (millis < 0 || millis >= (86400000))) {
160 throw  new IllegalArgumentException ();
161 }if (!this.useDaylight || year < this.startYear || era != 1) {
162 return this.rawOffset;
163 }return this.getOffset (cal, cdate, y, time);
164 }, "~N,~N,~N,~N,~N,~N");
165 Clazz.defineMethod (c$, "getOffset", 
166  function (cal, cdate, year, time) {
167 {
168 if (this.cacheStart != 0) {
169 if (time >= this.cacheStart && time < this.cacheEnd) {
170 return this.rawOffset + this.dstSavings;
171 }if (year == this.cacheYear) {
172 return this.rawOffset;
173 }}}var start = this.getStart (cal, cdate, year);
174 var end = this.getEnd (cal, cdate, year);
175 var offset = this.rawOffset;
176 if (start <= end) {
177 if (time >= start && time < end) {
178 offset += this.dstSavings;
179 }{
180 this.cacheYear = year;
181 this.cacheStart = start;
182 this.cacheEnd = end;
183 }} else {
184 if (time < end) {
185 start = this.getStart (cal, cdate, year - 1);
186 if (time >= start) {
187 offset += this.dstSavings;
188 }} else if (time >= start) {
189 end = this.getEnd (cal, cdate, year + 1);
190 if (time < end) {
191 offset += this.dstSavings;
192 }}if (start <= end) {
193 {
194 this.cacheYear = this.startYear - 1;
195 this.cacheStart = start;
196 this.cacheEnd = end;
197 }}}return offset;
198 }, "jssun.util.calendar.BaseCalendar,jssun.util.calendar.BaseCalendar.Date,~N,~N");
199 Clazz.defineMethod (c$, "getStart", 
200  function (cal, cdate, year) {
201 var time = this.startTime;
202 if (this.startTimeMode != 2) {
203 time -= this.rawOffset;
204 }return this.getTransition (cal, cdate, this.startMode, year, this.startMonth, this.startDay, this.startDayOfWeek, time);
205 }, "jssun.util.calendar.BaseCalendar,jssun.util.calendar.BaseCalendar.Date,~N");
206 Clazz.defineMethod (c$, "getEnd", 
207  function (cal, cdate, year) {
208 var time = this.endTime;
209 if (this.endTimeMode != 2) {
210 time -= this.rawOffset;
211 }if (this.endTimeMode == 0) {
212 time -= this.dstSavings;
213 }return this.getTransition (cal, cdate, this.endMode, year, this.endMonth, this.endDay, this.endDayOfWeek, time);
214 }, "jssun.util.calendar.BaseCalendar,jssun.util.calendar.BaseCalendar.Date,~N");
215 Clazz.defineMethod (c$, "getTransition", 
216  function (cal, cdate, mode, year, month, dayOfMonth, dayOfWeek, timeOfDay) {
217 cdate.setNormalizedYear (year);
218 cdate.setMonth (month + 1);
219 switch (mode) {
220 case 1:
221 cdate.setDayOfMonth (dayOfMonth);
222 break;
223 case 2:
224 cdate.setDayOfMonth (1);
225 if (dayOfMonth < 0) {
226 cdate.setDayOfMonth (cal.getMonthLength (cdate));
227 }cdate = cal.getNthDayOfWeek (dayOfMonth, dayOfWeek, cdate);
228 break;
229 case 3:
230 cdate.setDayOfMonth (dayOfMonth);
231 cdate = cal.getNthDayOfWeek (1, dayOfWeek, cdate);
232 break;
233 case 4:
234 cdate.setDayOfMonth (dayOfMonth);
235 cdate = cal.getNthDayOfWeek (-1, dayOfWeek, cdate);
236 break;
237 }
238 return cal.getTime (cdate) + timeOfDay;
239 }, "jssun.util.calendar.BaseCalendar,jssun.util.calendar.BaseCalendar.Date,~N,~N,~N,~N,~N,~N");
240 Clazz.overrideMethod (c$, "getRawOffset", 
241 function () {
242 return this.rawOffset;
243 });
244 Clazz.overrideMethod (c$, "setRawOffset", 
245 function (offsetMillis) {
246 this.rawOffset = offsetMillis;
247 }, "~N");
248 Clazz.defineMethod (c$, "setDSTSavings", 
249 function (millisSavedDuringDST) {
250 if (millisSavedDuringDST <= 0) {
251 throw  new IllegalArgumentException ("Illegal daylight saving value: " + millisSavedDuringDST);
252 }this.dstSavings = millisSavedDuringDST;
253 }, "~N");
254 Clazz.overrideMethod (c$, "getDSTSavings", 
255 function () {
256 if (this.useDaylight) {
257 return this.dstSavings;
258 }return 0;
259 });
260 Clazz.overrideMethod (c$, "useDaylightTime", 
261 function () {
262 return this.useDaylight;
263 });
264 Clazz.overrideMethod (c$, "inDaylightTime", 
265 function (date) {
266 return (this.getOffset (date.getTime ()) != this.rawOffset);
267 }, "java.util.Date");
268 Clazz.overrideMethod (c$, "hashCode", 
269 function () {
270 return this.startMonth ^ this.startDay ^ this.startDayOfWeek ^ this.startTime ^ this.endMonth ^ this.endDay ^ this.endDayOfWeek ^ this.endTime ^ this.rawOffset;
271 });
272 Clazz.overrideMethod (c$, "equals", 
273 function (obj) {
274 if (this === obj) {
275 return true;
276 }if (!(Clazz.instanceOf (obj, java.util.SimpleTimeZone))) {
277 return false;
278 }var that = obj;
279 return this.getID ().equals (that.getID ()) && this.hasSameRules (that);
280 }, "~O");
281 Clazz.overrideMethod (c$, "hasSameRules", 
282 function (other) {
283 if (this === other) {
284 return true;
285 }if (!(Clazz.instanceOf (other, java.util.SimpleTimeZone))) {
286 return false;
287 }var that = other;
288 return this.rawOffset == that.rawOffset && this.useDaylight == that.useDaylight && (!this.useDaylight || (this.dstSavings == that.dstSavings && this.startMode == that.startMode && this.startMonth == that.startMonth && this.startDay == that.startDay && this.startDayOfWeek == that.startDayOfWeek && this.startTime == that.startTime && this.startTimeMode == that.startTimeMode && this.endMode == that.endMode && this.endMonth == that.endMonth && this.endDay == that.endDay && this.endDayOfWeek == that.endDayOfWeek && this.endTime == that.endTime && this.endTimeMode == that.endTimeMode && this.startYear == that.startYear));
289 }, "java.util.TimeZone");
290 Clazz.overrideMethod (c$, "toString", 
291 function () {
292 return this.getClass ().getName () + "[id=" + this.getID () + ",offset=" + this.rawOffset + ",dstSavings=" + this.dstSavings + ",useDaylight=" + this.useDaylight + ",startYear=" + this.startYear + ",startMode=" + this.startMode + ",startMonth=" + this.startMonth + ",startDay=" + this.startDay + ",startDayOfWeek=" + this.startDayOfWeek + ",startTime=" + this.startTime + ",startTimeMode=" + this.startTimeMode + ",endMode=" + this.endMode + ",endMonth=" + this.endMonth + ",endDay=" + this.endDay + ",endDayOfWeek=" + this.endDayOfWeek + ",endTime=" + this.endTime + ",endTimeMode=" + this.endTimeMode + ']';
293 });
294 Clazz.defineMethod (c$, "invalidateCache", 
295  function () {
296 this.cacheYear = this.startYear - 1;
297 this.cacheStart = this.cacheEnd = 0;
298 });
299 Clazz.defineMethod (c$, "decodeRules", 
300  function () {
301 this.decodeStartRule ();
302 this.decodeEndRule ();
303 });
304 Clazz.defineMethod (c$, "decodeStartRule", 
305  function () {
306 this.useDaylight = (this.startDay != 0) && (this.endDay != 0);
307 if (this.startDay != 0) {
308 if (this.startMonth < 0 || this.startMonth > 11) {
309 throw  new IllegalArgumentException ("Illegal start month " + this.startMonth);
310 }if (this.startTime < 0 || this.startTime > 86400000) {
311 throw  new IllegalArgumentException ("Illegal start time " + this.startTime);
312 }if (this.startDayOfWeek == 0) {
313 this.startMode = 1;
314 } else {
315 if (this.startDayOfWeek > 0) {
316 this.startMode = 2;
317 } else {
318 this.startDayOfWeek = -this.startDayOfWeek;
319 if (this.startDay > 0) {
320 this.startMode = 3;
321 } else {
322 this.startDay = -this.startDay;
323 this.startMode = 4;
324 }}if (this.startDayOfWeek > 7) {
325 throw  new IllegalArgumentException ("Illegal start day of week " + this.startDayOfWeek);
326 }}if (this.startMode == 2) {
327 if (this.startDay < -5 || this.startDay > 5) {
328 throw  new IllegalArgumentException ("Illegal start day of week in month " + this.startDay);
329 }} else if (this.startDay < 1 || this.startDay > java.util.SimpleTimeZone.staticMonthLength[this.startMonth]) {
330 throw  new IllegalArgumentException ("Illegal start day " + this.startDay);
331 }}});
332 Clazz.defineMethod (c$, "decodeEndRule", 
333  function () {
334 this.useDaylight = (this.startDay != 0) && (this.endDay != 0);
335 if (this.endDay != 0) {
336 if (this.endMonth < 0 || this.endMonth > 11) {
337 throw  new IllegalArgumentException ("Illegal end month " + this.endMonth);
338 }if (this.endTime < 0 || this.endTime > 86400000) {
339 throw  new IllegalArgumentException ("Illegal end time " + this.endTime);
340 }if (this.endDayOfWeek == 0) {
341 this.endMode = 1;
342 } else {
343 if (this.endDayOfWeek > 0) {
344 this.endMode = 2;
345 } else {
346 this.endDayOfWeek = -this.endDayOfWeek;
347 if (this.endDay > 0) {
348 this.endMode = 3;
349 } else {
350 this.endDay = -this.endDay;
351 this.endMode = 4;
352 }}if (this.endDayOfWeek > 7) {
353 throw  new IllegalArgumentException ("Illegal end day of week " + this.endDayOfWeek);
354 }}if (this.endMode == 2) {
355 if (this.endDay < -5 || this.endDay > 5) {
356 throw  new IllegalArgumentException ("Illegal end day of week in month " + this.endDay);
357 }} else if (this.endDay < 1 || this.endDay > java.util.SimpleTimeZone.staticMonthLength[this.endMonth]) {
358 throw  new IllegalArgumentException ("Illegal end day " + this.endDay);
359 }}});
360 Clazz.defineStatics (c$,
361 "millisPerHour", 3600000,
362 "millisPerDay", 86400000,
363 "staticMonthLength",  Clazz.newByteArray (-1, [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]),
364 "staticLeapMonthLength",  Clazz.newByteArray (-1, [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]));
365 c$.gcal = c$.prototype.gcal = jssun.util.calendar.CalendarSystem.getGregorianCalendar ();
366 Clazz.defineStatics (c$,
367 "DOM_MODE", 1,
368 "DOW_IN_MONTH_MODE", 2,
369 "DOW_GE_DOM_MODE", 3,
370 "DOW_LE_DOM_MODE", 4,
371 "WALL_TIME", 0,
372 "STANDARD_TIME", 1,
373 "UTC_TIME", 2,
374 "currentSerialVersion", 2);
375 });