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