a514d9adad6a22cc99913d60e4f164104bca616f
[jalviewjs.git] / site / j2s / jssun / util / calendar / ZoneInfo.js
1 Clazz.declarePackage ("jssun.util.calendar");
2 Clazz.load (["java.util.TimeZone", "jssun.util.calendar.CalendarSystem"], "jssun.util.calendar.ZoneInfo", ["java.lang.IllegalArgumentException", "$.NullPointerException", "java.util.Date", "java.util.SimpleTimeZone"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.rawOffset = 0;
5 this.rawOffsetDiff = 0;
6 this.checksum = 0;
7 this.dstSavings = 0;
8 this.transitions = null;
9 this.offsets = null;
10 this.simpleTimeZoneParams = null;
11 this.willGMTOffsetChange = false;
12 this.dirty = false;
13 this.lastRule = null;
14 Clazz.instantialize (this, arguments);
15 }, jssun.util.calendar, "ZoneInfo", java.util.TimeZone);
16 Clazz.defineMethod (c$, "setRawOffsetReally", 
17 function (offset) {
18 this.rawOffset = offset;
19 }, "~N");
20 Clazz.makeConstructor (c$, 
21 function () {
22 Clazz.superConstructor (this, jssun.util.calendar.ZoneInfo, []);
23 });
24 Clazz.makeConstructor (c$, 
25 function (ID, rawOffset) {
26 this.construct (ID, rawOffset, 0, 0, null, null, null, false);
27 }, "~S,~N");
28 Clazz.makeConstructor (c$, 
29 function (ID, rawOffset, dstSavings, checksum, transitions, offsets, simpleTimeZoneParams, willGMTOffsetChange) {
30 Clazz.superConstructor (this, jssun.util.calendar.ZoneInfo, []);
31 this.setID (ID);
32 this.rawOffset = rawOffset;
33 this.dstSavings = dstSavings;
34 this.checksum = checksum;
35 this.transitions = transitions;
36 this.offsets = offsets;
37 this.simpleTimeZoneParams = simpleTimeZoneParams;
38 this.willGMTOffsetChange = willGMTOffsetChange;
39 }, "~S,~N,~N,~N,~A,~A,~A,~B");
40 Clazz.defineMethod (c$, "getOffset", 
41 function (date) {
42 return this.getOffsets (date, null, 0);
43 }, "~N");
44 Clazz.defineMethod (c$, "getOffsets", 
45 function (utc, offsets) {
46 return this.getOffsets (utc, offsets, 0);
47 }, "~N,~A");
48 Clazz.defineMethod (c$, "getOffsetsByStandard", 
49 function (standard, offsets) {
50 return this.getOffsets (standard, offsets, 1);
51 }, "~N,~A");
52 Clazz.defineMethod (c$, "getOffsetsByWall", 
53 function (wall, offsets) {
54 return this.getOffsets (wall, offsets, 2);
55 }, "~N,~A");
56 Clazz.defineMethod (c$, "getOffsets", 
57  function (date, offsets, type) {
58 if (this.transitions == null) {
59 var offset = this.getLastRawOffset ();
60 if (offsets != null) {
61 offsets[0] = offset;
62 offsets[1] = 0;
63 }return offset;
64 }date -= this.rawOffsetDiff;
65 var index = this.getTransitionIndex (date, type);
66 if (index < 0) {
67 var offset = this.getLastRawOffset ();
68 if (offsets != null) {
69 offsets[0] = offset;
70 offsets[1] = 0;
71 }return offset;
72 }if (index < this.transitions.length) {
73 var val = this.transitions[index];
74 var offset = this.offsets[(val & 15)] + this.rawOffsetDiff;
75 if (offsets != null) {
76 var dst = ((val >>> 4) & 0xf);
77 var save = (dst == 0) ? 0 : this.offsets[dst];
78 offsets[0] = offset - save;
79 offsets[1] = save;
80 }return offset;
81 }var tz = this.getLastRule ();
82 if (tz != null) {
83 var rawoffset = tz.getRawOffset ();
84 var msec = date;
85 if (type != 0) {
86 msec -= this.rawOffset;
87 }var dstoffset = tz.inDaylightTime ( new java.util.Date (msec)) ? tz.getDSTSavings () : 0;
88 if (offsets != null) {
89 offsets[0] = rawoffset;
90 offsets[1] = dstoffset;
91 }return rawoffset + dstoffset;
92 }var offset = this.getLastRawOffset ();
93 if (offsets != null) {
94 offsets[0] = offset;
95 offsets[1] = 0;
96 }return offset;
97 }, "~N,~A,~N");
98 Clazz.defineMethod (c$, "getTransitionIndex", 
99  function (date, type) {
100 var low = 0;
101 var high = this.transitions.length - 1;
102 while (low <= high) {
103 var mid = Clazz.doubleToInt ((low + high) / 2);
104 var val = this.transitions[mid];
105 var midVal = val >> 12;
106 if (type != 0) {
107 midVal += this.offsets[(val & 15)];
108 }if (type == 1) {
109 var dstIndex = ((val >>> 4) & 0xf);
110 if (dstIndex != 0) {
111 midVal -= this.offsets[dstIndex];
112 }}if (midVal < date) {
113 low = mid + 1;
114 } else if (midVal > date) {
115 high = mid - 1;
116 } else {
117 return mid;
118 }}
119 if (low >= this.transitions.length) {
120 return low;
121 }return low - 1;
122 }, "~N,~N");
123 Clazz.defineMethod (c$, "getOffset", 
124 function (era, year, month, day, dayOfWeek, milliseconds) {
125 if (milliseconds < 0 || milliseconds >= 86400000) {
126 throw  new IllegalArgumentException ();
127 }if (era == 0) {
128 year = 1 - year;
129 } else if (era != 1) {
130 throw  new IllegalArgumentException ();
131 }var date = jssun.util.calendar.ZoneInfo.gcal.newCalendarDate (null);
132 date.setDate (year, month + 1, day);
133 if (jssun.util.calendar.ZoneInfo.gcal.validate (date) == false) {
134 throw  new IllegalArgumentException ();
135 }if (dayOfWeek < 1 || dayOfWeek > 7) {
136 throw  new IllegalArgumentException ();
137 }if (this.transitions == null) {
138 return this.getLastRawOffset ();
139 }var dateInMillis = jssun.util.calendar.ZoneInfo.gcal.getTime (date) + milliseconds;
140 dateInMillis -= this.rawOffset;
141 return this.getOffsets (dateInMillis, null, 0);
142 }, "~N,~N,~N,~N,~N,~N");
143 Clazz.overrideMethod (c$, "setRawOffset", 
144 function (offsetMillis) {
145 if (offsetMillis == this.rawOffset + this.rawOffsetDiff) {
146 return;
147 }this.rawOffsetDiff = offsetMillis - this.rawOffset;
148 if (this.lastRule != null) {
149 this.lastRule.setRawOffset (offsetMillis);
150 }this.dirty = true;
151 }, "~N");
152 Clazz.defineMethod (c$, "getRawOffset", 
153 function () {
154 if (!this.willGMTOffsetChange) {
155 return this.rawOffset + this.rawOffsetDiff;
156 }var offsets =  Clazz.newIntArray (2, 0);
157 this.getOffsets (System.currentTimeMillis (), offsets, 0);
158 return offsets[0];
159 });
160 Clazz.defineMethod (c$, "isDirty", 
161 function () {
162 return this.dirty;
163 });
164 Clazz.defineMethod (c$, "getLastRawOffset", 
165  function () {
166 return this.rawOffset + this.rawOffsetDiff;
167 });
168 Clazz.defineMethod (c$, "useDaylightTime", 
169 function () {
170 return (this.simpleTimeZoneParams != null);
171 });
172 Clazz.overrideMethod (c$, "inDaylightTime", 
173 function (date) {
174 if (date == null) {
175 throw  new NullPointerException ();
176 }if (this.transitions == null) {
177 return false;
178 }var utc = date.getTime () - this.rawOffsetDiff;
179 var index = this.getTransitionIndex (utc, 0);
180 if (index < 0) {
181 return false;
182 }if (index < this.transitions.length) {
183 return (this.transitions[index] & 240) != 0;
184 }var tz = this.getLastRule ();
185 if (tz != null) {
186 return tz.inDaylightTime (date);
187 }return false;
188 }, "java.util.Date");
189 Clazz.overrideMethod (c$, "getDSTSavings", 
190 function () {
191 return this.dstSavings;
192 });
193 Clazz.overrideMethod (c$, "toString", 
194 function () {
195 return this.getClass ().getName () + "[id=\"" + this.getID () + "\"" + ",offset=" + this.getLastRawOffset () + ",dstSavings=" + this.dstSavings + ",useDaylight=" + this.useDaylightTime () + ",transitions=" + ((this.transitions != null) ? this.transitions.length : 0) + ",lastRule=" + (this.lastRule == null ? this.getLastRuleInstance () : this.lastRule) + "]";
196 });
197 Clazz.defineMethod (c$, "getLastRule", 
198  function () {
199 if (this.lastRule == null) {
200 this.lastRule = this.getLastRuleInstance ();
201 }return this.lastRule;
202 });
203 Clazz.defineMethod (c$, "getLastRuleInstance", 
204 function () {
205 if (this.simpleTimeZoneParams == null) {
206 return null;
207 }if (this.simpleTimeZoneParams.length == 10) {
208 return  new java.util.SimpleTimeZone (this.getLastRawOffset (), this.getID (), this.simpleTimeZoneParams[0], this.simpleTimeZoneParams[1], this.simpleTimeZoneParams[2], this.simpleTimeZoneParams[3], this.simpleTimeZoneParams[4], this.simpleTimeZoneParams[5], this.simpleTimeZoneParams[6], this.simpleTimeZoneParams[7], this.simpleTimeZoneParams[8], this.simpleTimeZoneParams[9], this.dstSavings);
209 }return  new java.util.SimpleTimeZone (this.getLastRawOffset (), this.getID (), this.simpleTimeZoneParams[0], this.simpleTimeZoneParams[1], this.simpleTimeZoneParams[2], this.simpleTimeZoneParams[3], this.simpleTimeZoneParams[4], this.simpleTimeZoneParams[5], this.simpleTimeZoneParams[6], this.simpleTimeZoneParams[7], this.dstSavings);
210 });
211 Clazz.defineMethod (c$, "clone", 
212 function () {
213 var zi = Clazz.superCall (this, jssun.util.calendar.ZoneInfo, "clone", []);
214 zi.lastRule = null;
215 return zi;
216 });
217 Clazz.overrideMethod (c$, "hashCode", 
218 function () {
219 return this.getLastRawOffset () ^ this.checksum;
220 });
221 Clazz.overrideMethod (c$, "equals", 
222 function (obj) {
223 if (this === obj) {
224 return true;
225 }if (!(Clazz.instanceOf (obj, jssun.util.calendar.ZoneInfo))) {
226 return false;
227 }var that = obj;
228 return (this.getID ().equals (that.getID ()) && (this.getLastRawOffset () == that.getLastRawOffset ()) && (this.checksum == that.checksum));
229 }, "~O");
230 Clazz.overrideMethod (c$, "hasSameRules", 
231 function (other) {
232 if (this === other) {
233 return true;
234 }if (other == null) {
235 return false;
236 }if (!(Clazz.instanceOf (other, jssun.util.calendar.ZoneInfo))) {
237 if (this.getRawOffset () != other.getRawOffset ()) {
238 return false;
239 }if ((this.transitions == null) && (this.useDaylightTime () == false) && (other.useDaylightTime () == false)) {
240 return true;
241 }return false;
242 }if (this.getLastRawOffset () != (other).getLastRawOffset ()) {
243 return false;
244 }return (this.checksum == (other).checksum);
245 }, "java.util.TimeZone");
246 c$.getAliasTable = Clazz.defineMethod (c$, "getAliasTable", 
247 function () {
248 var aliases = null;
249 var cache = jssun.util.calendar.ZoneInfo.aliasTable;
250 if (cache != null) {
251 aliases = cache;
252 if (aliases != null) {
253 return aliases;
254 }}return aliases;
255 });
256 Clazz.defineStatics (c$,
257 "UTC_TIME", 0,
258 "STANDARD_TIME", 1,
259 "WALL_TIME", 2,
260 "OFFSET_MASK", 0x0f,
261 "DST_MASK", 0xf0,
262 "DST_NSHIFT", 4,
263 "TRANSITION_NSHIFT", 12);
264 c$.gcal = c$.prototype.gcal = jssun.util.calendar.CalendarSystem.getGregorianCalendar ();
265 Clazz.defineStatics (c$,
266 "aliasTable", null);
267 });