c601819b67d55224f2d4e805549fab3c953c02df
[jalviewjs.git] / site / j2s / java / util / GregorianCalendar.js
1 Clazz.declarePackage ("java.util");\r
2 Clazz.load (["java.util.Calendar", "jssun.util.calendar.CalendarSystem", "$.Gregorian"], "java.util.GregorianCalendar", ["java.lang.ArrayIndexOutOfBoundsException", "$.IllegalArgumentException", "java.util.Date", "java.util.Locale", "$.TimeZone", "jssun.util.calendar.AbstractCalendar", "$.CalendarUtils", "$.ZoneInfo"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.gregorianCutover = -12219292800000;\r
5 this.gregorianCutoverDate = 577736;\r
6 this.gregorianCutoverYear = 1582;\r
7 this.gregorianCutoverYearJulian = 1582;\r
8 this.gdate = null;\r
9 this.cdate = null;\r
10 this.calsys = null;\r
11 this.zoneOffsets = null;\r
12 this.originalFields = null;\r
13 this.cachedFixedDate = -9223372036854775808;\r
14 Clazz.instantialize (this, arguments);\r
15 }, java.util, "GregorianCalendar", java.util.Calendar);\r
16 Clazz.makeConstructor (c$, \r
17 function () {\r
18 this.construct (java.util.TimeZone.getDefaultRef (), java.util.Locale.getDefault ());\r
19 this.setZoneShared (true);\r
20 });\r
21 Clazz.makeConstructor (c$, \r
22 function (zone) {\r
23 this.construct (zone, java.util.Locale.getDefault ());\r
24 }, "java.util.TimeZone");\r
25 Clazz.makeConstructor (c$, \r
26 function (aLocale) {\r
27 this.construct (java.util.TimeZone.getDefaultRef (), aLocale);\r
28 this.setZoneShared (true);\r
29 }, "java.util.Locale");\r
30 Clazz.makeConstructor (c$, \r
31 function (zone, aLocale) {\r
32 Clazz.superConstructor (this, java.util.GregorianCalendar, [zone, aLocale]);\r
33 this.gdate = java.util.GregorianCalendar.gcal.newCalendarDate (zone);\r
34 this.setTimeInMillis (System.currentTimeMillis ());\r
35 }, "java.util.TimeZone,java.util.Locale");\r
36 Clazz.makeConstructor (c$, \r
37 function (year, month, dayOfMonth) {\r
38 this.construct (year, month, dayOfMonth, 0, 0, 0, 0);\r
39 }, "~N,~N,~N");\r
40 Clazz.makeConstructor (c$, \r
41 function (year, month, dayOfMonth, hourOfDay, minute) {\r
42 this.construct (year, month, dayOfMonth, hourOfDay, minute, 0, 0);\r
43 }, "~N,~N,~N,~N,~N");\r
44 Clazz.makeConstructor (c$, \r
45 function (year, month, dayOfMonth, hourOfDay, minute, second) {\r
46 this.construct (year, month, dayOfMonth, hourOfDay, minute, second, 0);\r
47 }, "~N,~N,~N,~N,~N,~N");\r
48 Clazz.makeConstructor (c$, \r
49 function (year, month, dayOfMonth, hourOfDay, minute, second, millis) {\r
50 Clazz.superConstructor (this, java.util.GregorianCalendar);\r
51 this.gdate = java.util.GregorianCalendar.gcal.newCalendarDate (this.getZone ());\r
52 this.set (1, year);\r
53 this.set (2, month);\r
54 this.set (5, dayOfMonth);\r
55 if (hourOfDay >= 12 && hourOfDay <= 23) {\r
56 this.internalSet (9, 1);\r
57 this.internalSet (10, hourOfDay - 12);\r
58 } else {\r
59 this.internalSet (10, hourOfDay);\r
60 }this.setFieldsComputed (1536);\r
61 this.set (11, hourOfDay);\r
62 this.set (12, minute);\r
63 this.set (13, second);\r
64 this.internalSet (14, millis);\r
65 }, "~N,~N,~N,~N,~N,~N,~N");\r
66 Clazz.defineMethod (c$, "getGregorianChange", \r
67 function () {\r
68 return  new java.util.Date (this.gregorianCutover);\r
69 });\r
70 Clazz.defineMethod (c$, "isLeapYear", \r
71 function (year) {\r
72 if ((year & 3) != 0) {\r
73 return false;\r
74 }if (year > this.gregorianCutoverYear) {\r
75 return (year % 100 != 0) || (year % 400 == 0);\r
76 }if (year < this.gregorianCutoverYearJulian) {\r
77 return true;\r
78 }var gregorian;\r
79 if (this.gregorianCutoverYear == this.gregorianCutoverYearJulian) {\r
80 var d = this.getCalendarDate (this.gregorianCutoverDate);\r
81 gregorian = d.getMonth () < 3;\r
82 } else {\r
83 gregorian = year == this.gregorianCutoverYear;\r
84 }return gregorian ? (year % 100 != 0) || (year % 400 == 0) : true;\r
85 }, "~N");\r
86 Clazz.defineMethod (c$, "equals", \r
87 function (obj) {\r
88 return Clazz.instanceOf (obj, java.util.GregorianCalendar) && Clazz.superCall (this, java.util.GregorianCalendar, "equals", [obj]) && this.gregorianCutover == (obj).gregorianCutover;\r
89 }, "~O");\r
90 Clazz.defineMethod (c$, "hashCode", \r
91 function () {\r
92 return Clazz.superCall (this, java.util.GregorianCalendar, "hashCode", []) ^ this.gregorianCutoverDate;\r
93 });\r
94 Clazz.overrideMethod (c$, "add", \r
95 function (field, amount) {\r
96 if (amount == 0) {\r
97 return;\r
98 }if (field < 0 || field >= 15) {\r
99 throw  new IllegalArgumentException ();\r
100 }this.complete ();\r
101 if (field == 1) {\r
102 var year = this.internalGet (1);\r
103 if (this.internalGetEra () == 1) {\r
104 year += amount;\r
105 if (year > 0) {\r
106 this.set (1, year);\r
107 } else {\r
108 this.set (1, 1 - year);\r
109 this.set (0, 0);\r
110 }} else {\r
111 year -= amount;\r
112 if (year > 0) {\r
113 this.set (1, year);\r
114 } else {\r
115 this.set (1, 1 - year);\r
116 this.set (0, 1);\r
117 }}this.pinDayOfMonth ();\r
118 } else if (field == 2) {\r
119 var month = this.internalGet (2) + amount;\r
120 var year = this.internalGet (1);\r
121 var y_amount;\r
122 if (month >= 0) {\r
123 y_amount = Clazz.doubleToInt (month / 12);\r
124 } else {\r
125 y_amount = Clazz.doubleToInt ((month + 1) / 12) - 1;\r
126 }if (y_amount != 0) {\r
127 if (this.internalGetEra () == 1) {\r
128 year += y_amount;\r
129 if (year > 0) {\r
130 this.set (1, year);\r
131 } else {\r
132 this.set (1, 1 - year);\r
133 this.set (0, 0);\r
134 }} else {\r
135 year -= y_amount;\r
136 if (year > 0) {\r
137 this.set (1, year);\r
138 } else {\r
139 this.set (1, 1 - year);\r
140 this.set (0, 1);\r
141 }}}if (month >= 0) {\r
142 this.set (2, (month % 12));\r
143 } else {\r
144 month %= 12;\r
145 if (month < 0) {\r
146 month += 12;\r
147 }this.set (2, 0 + month);\r
148 }this.pinDayOfMonth ();\r
149 } else if (field == 0) {\r
150 var era = this.internalGet (0) + amount;\r
151 if (era < 0) {\r
152 era = 0;\r
153 }if (era > 1) {\r
154 era = 1;\r
155 }this.set (0, era);\r
156 } else {\r
157 var delta = amount;\r
158 var timeOfDay = 0;\r
159 switch (field) {\r
160 case 10:\r
161 case 11:\r
162 delta *= 3600000;\r
163 break;\r
164 case 12:\r
165 delta *= 60000;\r
166 break;\r
167 case 13:\r
168 delta *= 1000;\r
169 break;\r
170 case 14:\r
171 break;\r
172 case 3:\r
173 case 4:\r
174 case 8:\r
175 delta *= 7;\r
176 break;\r
177 case 5:\r
178 case 6:\r
179 case 7:\r
180 break;\r
181 case 9:\r
182 delta = Clazz.doubleToInt (amount / 2);\r
183 timeOfDay = 12 * (amount % 2);\r
184 break;\r
185 }\r
186 if (field >= 10) {\r
187 this.setTimeInMillis (this.time + delta);\r
188 return;\r
189 }var fd = this.getCurrentFixedDate ();\r
190 timeOfDay += this.internalGet (11);\r
191 timeOfDay *= 60;\r
192 timeOfDay += this.internalGet (12);\r
193 timeOfDay *= 60;\r
194 timeOfDay += this.internalGet (13);\r
195 timeOfDay *= 1000;\r
196 timeOfDay += this.internalGet (14);\r
197 if (timeOfDay >= 86400000) {\r
198 fd++;\r
199 timeOfDay -= 86400000;\r
200 } else if (timeOfDay < 0) {\r
201 fd--;\r
202 timeOfDay += 86400000;\r
203 }fd += delta;\r
204 var zoneOffset = this.internalGet (15) + this.internalGet (16);\r
205 this.setTimeInMillis ((fd - 719163) * 86400000 + timeOfDay - zoneOffset);\r
206 zoneOffset -= this.internalGet (15) + this.internalGet (16);\r
207 if (zoneOffset != 0) {\r
208 this.setTimeInMillis (this.time + zoneOffset);\r
209 var fd2 = this.getCurrentFixedDate ();\r
210 if (fd2 != fd) {\r
211 this.setTimeInMillis (this.time - zoneOffset);\r
212 }}}}, "~N,~N");\r
213 Clazz.defineMethod (c$, "roll", \r
214 function (field, up) {\r
215 this.roll (field, up ? 1 : -1);\r
216 }, "~N,~B");\r
217 Clazz.defineMethod (c$, "roll", \r
218 function (field, amount) {\r
219 if (amount == 0) {\r
220 return;\r
221 }if (field < 0 || field >= 15) {\r
222 throw  new IllegalArgumentException ();\r
223 }this.complete ();\r
224 var min = this.getMinimum (field);\r
225 var max = this.getMaximum (field);\r
226 switch (field) {\r
227 case 9:\r
228 case 0:\r
229 case 1:\r
230 case 12:\r
231 case 13:\r
232 case 14:\r
233 break;\r
234 case 10:\r
235 case 11:\r
236 {\r
237 var unit = max + 1;\r
238 var h = this.internalGet (field);\r
239 var nh = (h + amount) % unit;\r
240 if (nh < 0) {\r
241 nh += unit;\r
242 }this.time += 3600000 * (nh - h);\r
243 var d = this.calsys.getCalendarDate (this.time, this.getZone ());\r
244 if (this.internalGet (5) != d.getDayOfMonth ()) {\r
245 d.setDate (this.internalGet (1), this.internalGet (2) + 1, this.internalGet (5));\r
246 if (field == 10) {\r
247 d.addHours (12);\r
248 }this.time = this.calsys.getTime (d);\r
249 }var hourOfDay = d.getHours ();\r
250 this.internalSet (field, hourOfDay % unit);\r
251 if (field == 10) {\r
252 this.internalSet (11, hourOfDay);\r
253 } else {\r
254 this.internalSet (9, Clazz.doubleToInt (hourOfDay / 12));\r
255 this.internalSet (10, hourOfDay % 12);\r
256 }var zoneOffset = d.getZoneOffset ();\r
257 var saving = d.getDaylightSaving ();\r
258 this.internalSet (15, zoneOffset - saving);\r
259 this.internalSet (16, saving);\r
260 return;\r
261 }case 2:\r
262 {\r
263 var mon = (this.internalGet (2) + amount) % 12;\r
264 if (mon < 0) {\r
265 mon += 12;\r
266 }this.set (2, mon);\r
267 var monthLen = this.monthLength (mon);\r
268 if (this.internalGet (5) > monthLen) {\r
269 this.set (5, monthLen);\r
270 }return;\r
271 }case 3:\r
272 {\r
273 var y = this.cdate.getNormalizedYear ();\r
274 max = this.getActualMaximum (3);\r
275 this.set (7, this.internalGet (7));\r
276 var woy = this.internalGet (3);\r
277 var value = woy + amount;\r
278 if (value > min && value < max) {\r
279 this.set (3, value);\r
280 return;\r
281 }var fd = this.getCurrentFixedDate ();\r
282 var day1 = fd - (7 * (woy - min));\r
283 if (this.calsys.getYearFromFixedDate (day1) != y) {\r
284 min++;\r
285 }fd += 7 * (max - this.internalGet (3));\r
286 if (this.calsys.getYearFromFixedDate (fd) != y) {\r
287 max--;\r
288 }break;\r
289 }case 4:\r
290 {\r
291 var dow = this.internalGet (7) - this.getFirstDayOfWeek ();\r
292 if (dow < 0) {\r
293 dow += 7;\r
294 }var fd = this.getCurrentFixedDate ();\r
295 var month1;\r
296 var monthLength;\r
297 month1 = fd - this.internalGet (5) + 1;\r
298 monthLength = this.calsys.getMonthLength (this.cdate);\r
299 var monthDay1st = jssun.util.calendar.AbstractCalendar.getDayOfWeekDateOnOrBefore (month1 + 6, this.getFirstDayOfWeek ());\r
300 if ((monthDay1st - month1) >= this.getMinimalDaysInFirstWeek ()) {\r
301 monthDay1st -= 7;\r
302 }max = this.getActualMaximum (field);\r
303 var value = java.util.GregorianCalendar.getRolledValue (this.internalGet (field), amount, 1, max) - 1;\r
304 var nfd = monthDay1st + value * 7 + dow;\r
305 if (nfd < month1) {\r
306 nfd = month1;\r
307 } else if (nfd >= (month1 + monthLength)) {\r
308 nfd = month1 + monthLength - 1;\r
309 }var dayOfMonth;\r
310 dayOfMonth = (nfd - month1) + 1;\r
311 this.set (5, dayOfMonth);\r
312 return;\r
313 }case 5:\r
314 {\r
315 max = this.calsys.getMonthLength (this.cdate);\r
316 break;\r
317 }case 6:\r
318 {\r
319 max = this.getActualMaximum (field);\r
320 break;\r
321 }case 7:\r
322 {\r
323 var weekOfYear = this.internalGet (3);\r
324 this.set (3, weekOfYear);\r
325 max = 7;\r
326 break;\r
327 }case 8:\r
328 {\r
329 min = 1;\r
330 var dom = this.internalGet (5);\r
331 var monthLength = this.calsys.getMonthLength (this.cdate);\r
332 var lastDays = monthLength % 7;\r
333 max = Clazz.doubleToInt (monthLength / 7);\r
334 var x = (dom - 1) % 7;\r
335 if (x < lastDays) {\r
336 max++;\r
337 }this.set (7, this.internalGet (7));\r
338 break;\r
339 }}\r
340 this.set (field, java.util.GregorianCalendar.getRolledValue (this.internalGet (field), amount, min, max));\r
341 }, "~N,~N");\r
342 Clazz.overrideMethod (c$, "getMinimum", \r
343 function (field) {\r
344 return java.util.GregorianCalendar.MIN_VALUES[field];\r
345 }, "~N");\r
346 Clazz.overrideMethod (c$, "getMaximum", \r
347 function (field) {\r
348 switch (field) {\r
349 case 2:\r
350 case 5:\r
351 case 6:\r
352 case 3:\r
353 case 4:\r
354 case 8:\r
355 case 1:\r
356 {\r
357 if (this.gregorianCutoverYear > 200) {\r
358 break;\r
359 }var gc = this.clone ();\r
360 gc.setLenient (true);\r
361 gc.setTimeInMillis (this.gregorianCutover);\r
362 var v1 = gc.getActualMaximum (field);\r
363 gc.setTimeInMillis (this.gregorianCutover - 1);\r
364 var v2 = gc.getActualMaximum (field);\r
365 return Math.max (java.util.GregorianCalendar.MAX_VALUES[field], Math.max (v1, v2));\r
366 }}\r
367 return java.util.GregorianCalendar.MAX_VALUES[field];\r
368 }, "~N");\r
369 Clazz.overrideMethod (c$, "getGreatestMinimum", \r
370 function (field) {\r
371 return java.util.GregorianCalendar.MIN_VALUES[field];\r
372 }, "~N");\r
373 Clazz.overrideMethod (c$, "getLeastMaximum", \r
374 function (field) {\r
375 switch (field) {\r
376 case 2:\r
377 case 5:\r
378 case 6:\r
379 case 3:\r
380 case 4:\r
381 case 8:\r
382 case 1:\r
383 {\r
384 var gc = this.clone ();\r
385 gc.setLenient (true);\r
386 gc.setTimeInMillis (this.gregorianCutover);\r
387 var v1 = gc.getActualMaximum (field);\r
388 gc.setTimeInMillis (this.gregorianCutover - 1);\r
389 var v2 = gc.getActualMaximum (field);\r
390 return Math.min (java.util.GregorianCalendar.LEAST_MAX_VALUES[field], Math.min (v1, v2));\r
391 }}\r
392 return java.util.GregorianCalendar.LEAST_MAX_VALUES[field];\r
393 }, "~N");\r
394 Clazz.overrideMethod (c$, "getActualMinimum", \r
395 function (field) {\r
396 if (field == 5) {\r
397 }return this.getMinimum (field);\r
398 }, "~N");\r
399 Clazz.overrideMethod (c$, "getActualMaximum", \r
400 function (field) {\r
401 var fieldsForFixedMax = 130689;\r
402 if ((130689 & (1 << field)) != 0) {\r
403 return this.getMaximum (field);\r
404 }var gc = this.getNormalizedCalendar ();\r
405 var date = gc.cdate;\r
406 var cal = gc.calsys;\r
407 var value = -1;\r
408 var d;\r
409 var dd;\r
410 switch (field) {\r
411 case 2:\r
412 {\r
413 }break;\r
414 case 5:\r
415 value = cal.getMonthLength (date);\r
416 break;\r
417 case 6:\r
418 value = cal.getYearLength (date);\r
419 break;\r
420 case 3:\r
421 {\r
422 dd = cal.newCalendarDate (java.util.TimeZone.NO_TIMEZONE);\r
423 dd.setDate (date.getYear (), 1, 1);\r
424 var dayOfWeek = cal.getDayOfWeek (dd);\r
425 dayOfWeek -= this.getFirstDayOfWeek ();\r
426 if (dayOfWeek < 0) {\r
427 dayOfWeek += 7;\r
428 }value = 52;\r
429 var magic = dayOfWeek + this.getMinimalDaysInFirstWeek () - 1;\r
430 if ((magic == 6) || (date.isLeapYear () && (magic == 5 || magic == 12))) {\r
431 value++;\r
432 }}break;\r
433 case 4:\r
434 dd = cal.newCalendarDate (null);\r
435 dd.setDate (date.getYear (), date.getMonth (), 1);\r
436 var dayOfWeek = cal.getDayOfWeek (dd);\r
437 var monthLength = cal.getMonthLength (dd);\r
438 dayOfWeek -= this.getFirstDayOfWeek ();\r
439 if (dayOfWeek < 0) {\r
440 dayOfWeek += 7;\r
441 }var nDaysFirstWeek = 7 - dayOfWeek;\r
442 value = 3;\r
443 if (nDaysFirstWeek >= this.getMinimalDaysInFirstWeek ()) {\r
444 value++;\r
445 }monthLength -= nDaysFirstWeek + 21;\r
446 if (monthLength > 0) {\r
447 value++;\r
448 if (monthLength > 7) {\r
449 value++;\r
450 }}break;\r
451 case 8:\r
452 {\r
453 var ndays;\r
454 var dow1;\r
455 var dow = date.getDayOfWeek ();\r
456 d = date.clone ();\r
457 ndays = cal.getMonthLength (d);\r
458 d.setDayOfMonth (1);\r
459 cal.normalize (d);\r
460 dow1 = d.getDayOfWeek ();\r
461 var x = dow - dow1;\r
462 if (x < 0) {\r
463 x += 7;\r
464 }ndays -= x;\r
465 value = Clazz.doubleToInt ((ndays + 6) / 7);\r
466 }break;\r
467 case 1:\r
468 {\r
469 if (gc === this) {\r
470 gc = this.clone ();\r
471 }var current = gc.getYearOffsetInMillis ();\r
472 if (gc.internalGetEra () == 1) {\r
473 gc.setTimeInMillis (9223372036854775807);\r
474 value = gc.get (1);\r
475 var maxEnd = gc.getYearOffsetInMillis ();\r
476 if (current > maxEnd) {\r
477 value--;\r
478 }} else {\r
479 var mincal = java.util.GregorianCalendar.gcal;\r
480 dd = mincal.getCalendarDate (-9223372036854775808, this.getZone ());\r
481 var maxEnd = (cal.getDayOfYear (dd) - 1) * 24 + dd.getHours ();\r
482 maxEnd *= 60;\r
483 maxEnd += dd.getMinutes ();\r
484 maxEnd *= 60;\r
485 maxEnd += dd.getSeconds ();\r
486 maxEnd *= 1000;\r
487 maxEnd += dd.getMillis ();\r
488 value = dd.getYear ();\r
489 if (value <= 0) {\r
490 value = 1 - value;\r
491 }if (current < maxEnd) {\r
492 value--;\r
493 }}}break;\r
494 default:\r
495 throw  new ArrayIndexOutOfBoundsException (field);\r
496 }\r
497 return value;\r
498 }, "~N");\r
499 Clazz.defineMethod (c$, "getYearOffsetInMillis", \r
500  function () {\r
501 var t = (this.internalGet (6) - 1) * 24;\r
502 t += this.internalGet (11);\r
503 t *= 60;\r
504 t += this.internalGet (12);\r
505 t *= 60;\r
506 t += this.internalGet (13);\r
507 t *= 1000;\r
508 return t + this.internalGet (14) - (this.internalGet (15) + this.internalGet (16));\r
509 });\r
510 Clazz.defineMethod (c$, "clone", \r
511 function () {\r
512 var other = Clazz.superCall (this, java.util.GregorianCalendar, "clone", []);\r
513 other.gdate = this.gdate.clone ();\r
514 if (this.cdate != null) {\r
515 if (this.cdate !== this.gdate) {\r
516 other.cdate = this.cdate.clone ();\r
517 } else {\r
518 other.cdate = other.gdate;\r
519 }}other.originalFields = null;\r
520 other.zoneOffsets = null;\r
521 return other;\r
522 });\r
523 Clazz.defineMethod (c$, "getTimeZone", \r
524 function () {\r
525 var zone = Clazz.superCall (this, java.util.GregorianCalendar, "getTimeZone", []);\r
526 this.gdate.setZone (zone);\r
527 if (this.cdate != null && this.cdate !== this.gdate) {\r
528 this.cdate.setZone (zone);\r
529 }return zone;\r
530 });\r
531 Clazz.defineMethod (c$, "setTimeZone", \r
532 function (zone) {\r
533 Clazz.superCall (this, java.util.GregorianCalendar, "setTimeZone", [zone]);\r
534 this.gdate.setZone (zone);\r
535 if (this.cdate != null && this.cdate !== this.gdate) {\r
536 this.cdate.setZone (zone);\r
537 }}, "java.util.TimeZone");\r
538 Clazz.defineMethod (c$, "computeFields", \r
539 function () {\r
540 var mask = 0;\r
541 if (this.isPartiallyNormalized ()) {\r
542 mask = this.getSetStateFields ();\r
543 var fieldMask = ~mask & 131071;\r
544 if (fieldMask != 0 || this.calsys == null) {\r
545 mask |= this.computeFields (fieldMask, mask & (98304));\r
546 }} else {\r
547 mask = 131071;\r
548 this.computeFields (mask, 0);\r
549 }this.setFieldsComputed (mask);\r
550 });\r
551 Clazz.defineMethod (c$, "computeFields", \r
552  function (fieldMask, tzMask) {\r
553 var zoneOffset = 0;\r
554 var tz = this.getZone ();\r
555 if (this.zoneOffsets == null) {\r
556 this.zoneOffsets =  Clazz.newIntArray (2, 0);\r
557 }if (tzMask != (98304)) {\r
558 if (Clazz.instanceOf (tz, jssun.util.calendar.ZoneInfo)) {\r
559 zoneOffset = (tz).getOffsets (this.time, this.zoneOffsets);\r
560 } else {\r
561 zoneOffset = tz.getOffset (this.time);\r
562 this.zoneOffsets[0] = tz.getRawOffset ();\r
563 this.zoneOffsets[1] = zoneOffset - this.zoneOffsets[0];\r
564 }}if (tzMask != 0) {\r
565 if (java.util.Calendar.isFieldSet (tzMask, 15)) {\r
566 this.zoneOffsets[0] = this.internalGet (15);\r
567 }if (java.util.Calendar.isFieldSet (tzMask, 16)) {\r
568 this.zoneOffsets[1] = this.internalGet (16);\r
569 }zoneOffset = this.zoneOffsets[0] + this.zoneOffsets[1];\r
570 }var fixedDate = Clazz.doubleToInt (zoneOffset / 86400000);\r
571 var timeOfDay = zoneOffset % 86400000;\r
572 fixedDate += Clazz.doubleToInt (this.time / 86400000);\r
573 timeOfDay += (this.time % 86400000);\r
574 if (timeOfDay >= 86400000) {\r
575 timeOfDay -= 86400000;\r
576 ++fixedDate;\r
577 } else {\r
578 while (timeOfDay < 0) {\r
579 timeOfDay += 86400000;\r
580 --fixedDate;\r
581 }\r
582 }fixedDate += 719163;\r
583 var era = 1;\r
584 var year;\r
585 if (fixedDate != this.cachedFixedDate) {\r
586 java.util.GregorianCalendar.gcal.getCalendarDateFromFixedDate (this.gdate, fixedDate);\r
587 this.cachedFixedDate = fixedDate;\r
588 }year = this.gdate.getYear ();\r
589 if (year <= 0) {\r
590 year = 1 - year;\r
591 era = 0;\r
592 }this.calsys = java.util.GregorianCalendar.gcal;\r
593 this.cdate = this.gdate;\r
594 this.internalSet (0, era);\r
595 this.internalSet (1, year);\r
596 var mask = fieldMask | (3);\r
597 var month = this.cdate.getMonth () - 1;\r
598 var dayOfMonth = this.cdate.getDayOfMonth ();\r
599 if ((fieldMask & (164)) != 0) {\r
600 this.internalSet (2, month);\r
601 this.internalSet (5, dayOfMonth);\r
602 this.internalSet (7, this.cdate.getDayOfWeek ());\r
603 mask |= 164;\r
604 }if ((fieldMask & (32256)) != 0) {\r
605 if (timeOfDay != 0) {\r
606 var hours = Clazz.doubleToInt (timeOfDay / 3600000);\r
607 this.internalSet (11, hours);\r
608 this.internalSet (9, Clazz.doubleToInt (hours / 12));\r
609 this.internalSet (10, hours % 12);\r
610 var r = timeOfDay % 3600000;\r
611 this.internalSet (12, Clazz.doubleToInt (r / 60000));\r
612 r %= 60000;\r
613 this.internalSet (13, Clazz.doubleToInt (r / 1000));\r
614 this.internalSet (14, r % 1000);\r
615 } else {\r
616 this.internalSet (11, 0);\r
617 this.internalSet (9, 0);\r
618 this.internalSet (10, 0);\r
619 this.internalSet (12, 0);\r
620 this.internalSet (13, 0);\r
621 this.internalSet (14, 0);\r
622 }mask |= (32256);\r
623 }if ((fieldMask & (98304)) != 0) {\r
624 this.internalSet (15, this.zoneOffsets[0]);\r
625 this.internalSet (16, this.zoneOffsets[1]);\r
626 mask |= (98304);\r
627 }if ((fieldMask & (344)) != 0) {\r
628 var normalizedYear = this.cdate.getNormalizedYear ();\r
629 var fixedDateJan1 = this.calsys.getFixedDate (normalizedYear, 1, 1, this.cdate);\r
630 var dayOfYear = (fixedDate - fixedDateJan1) + 1;\r
631 var fixedDateMonth1 = fixedDate - dayOfMonth + 1;\r
632 var cutoverYear = (this.calsys === java.util.GregorianCalendar.gcal) ? this.gregorianCutoverYear : this.gregorianCutoverYearJulian;\r
633 var relativeDayOfMonth = dayOfMonth - 1;\r
634 if (normalizedYear == cutoverYear) {\r
635 var realDayOfYear = (fixedDate - fixedDateJan1) + 1;\r
636 dayOfYear = realDayOfYear;\r
637 relativeDayOfMonth = (fixedDate - fixedDateMonth1);\r
638 }this.internalSet (6, dayOfYear);\r
639 this.internalSet (8, Clazz.doubleToInt (relativeDayOfMonth / 7) + 1);\r
640 var weekOfYear = this.getWeekNumber (fixedDateJan1, fixedDate);\r
641 if (weekOfYear == 0) {\r
642 var fixedDec31 = fixedDateJan1 - 1;\r
643 var prevJan1;\r
644 prevJan1 = fixedDateJan1 - 365;\r
645 if (jssun.util.calendar.CalendarUtils.isGregorianLeapYear (normalizedYear - 1)) {\r
646 --prevJan1;\r
647 }weekOfYear = this.getWeekNumber (prevJan1, fixedDec31);\r
648 } else {\r
649 if (normalizedYear > this.gregorianCutoverYear || normalizedYear < (this.gregorianCutoverYearJulian - 1)) {\r
650 if (weekOfYear >= 52) {\r
651 var nextJan1 = fixedDateJan1 + 365;\r
652 if (this.cdate.isLeapYear ()) {\r
653 nextJan1++;\r
654 }var nextJan1st = jssun.util.calendar.AbstractCalendar.getDayOfWeekDateOnOrBefore (nextJan1 + 6, this.getFirstDayOfWeek ());\r
655 var ndays = (nextJan1st - nextJan1);\r
656 if (ndays >= this.getMinimalDaysInFirstWeek () && fixedDate >= (nextJan1st - 7)) {\r
657 weekOfYear = 1;\r
658 }}} else {\r
659 var calForJan1 = this.calsys;\r
660 var nextYear = normalizedYear + 1;\r
661 var nextJan1 = calForJan1.getFixedDate (nextYear, 1, 1, null);\r
662 if (nextJan1 < fixedDate) {\r
663 nextJan1 = this.gregorianCutoverDate;\r
664 calForJan1 = java.util.GregorianCalendar.gcal;\r
665 }var nextJan1st = jssun.util.calendar.AbstractCalendar.getDayOfWeekDateOnOrBefore (nextJan1 + 6, this.getFirstDayOfWeek ());\r
666 var ndays = (nextJan1st - nextJan1);\r
667 if (ndays >= this.getMinimalDaysInFirstWeek () && fixedDate >= (nextJan1st - 7)) {\r
668 weekOfYear = 1;\r
669 }}}this.internalSet (3, weekOfYear);\r
670 this.internalSet (4, this.getWeekNumber (fixedDateMonth1, fixedDate));\r
671 mask |= (344);\r
672 }return mask;\r
673 }, "~N,~N");\r
674 Clazz.defineMethod (c$, "getWeekNumber", \r
675  function (fixedDay1, fixedDate) {\r
676 var fixedDay1st = jssun.util.calendar.AbstractCalendar.getDayOfWeekDateOnOrBefore (fixedDay1 + 6, this.getFirstDayOfWeek ());\r
677 var ndays = (fixedDay1st - fixedDay1);\r
678 if (ndays >= this.getMinimalDaysInFirstWeek ()) {\r
679 fixedDay1st -= 7;\r
680 }var normalizedDayOfPeriod = (fixedDate - fixedDay1st);\r
681 if (normalizedDayOfPeriod >= 0) {\r
682 return Clazz.doubleToInt (normalizedDayOfPeriod / 7) + 1;\r
683 }return jssun.util.calendar.CalendarUtils.floorDivide (normalizedDayOfPeriod, 7) + 1;\r
684 }, "~N,~N");\r
685 Clazz.overrideMethod (c$, "computeTime", \r
686 function () {\r
687 if (!this.isLenient ()) {\r
688 if (this.originalFields == null) {\r
689 this.originalFields =  Clazz.newIntArray (17, 0);\r
690 }for (var field = 0; field < 17; field++) {\r
691 var value = this.internalGet (field);\r
692 if (this.isExternallySet (field)) {\r
693 if (value < this.getMinimum (field) || value > this.getMaximum (field)) {\r
694 throw  new IllegalArgumentException (java.util.Calendar.getFieldName (field));\r
695 }}this.originalFields[field] = value;\r
696 }\r
697 }var fieldMask = this.selectFields ();\r
698 var year = this.isSet (1) ? this.internalGet (1) : 1970;\r
699 var era = this.internalGetEra ();\r
700 if (era == 0) {\r
701 year = 1 - year;\r
702 } else if (era != 1) {\r
703 throw  new IllegalArgumentException ("Invalid era");\r
704 }if (year <= 0 && !this.isSet (0)) {\r
705 fieldMask |= 1;\r
706 this.setFieldsComputed (1);\r
707 }var timeOfDay = 0;\r
708 if (java.util.Calendar.isFieldSet (fieldMask, 11)) {\r
709 timeOfDay += this.internalGet (11);\r
710 } else {\r
711 timeOfDay += this.internalGet (10);\r
712 if (java.util.Calendar.isFieldSet (fieldMask, 9)) {\r
713 timeOfDay += 12 * this.internalGet (9);\r
714 }}timeOfDay *= 60;\r
715 timeOfDay += this.internalGet (12);\r
716 timeOfDay *= 60;\r
717 timeOfDay += this.internalGet (13);\r
718 timeOfDay *= 1000;\r
719 timeOfDay += this.internalGet (14);\r
720 var fixedDate = Clazz.doubleToInt (timeOfDay / 86400000);\r
721 timeOfDay %= 86400000;\r
722 while (timeOfDay < 0) {\r
723 timeOfDay += 86400000;\r
724 --fixedDate;\r
725 }\r
726 calculateFixedDate : {\r
727 var gfd;\r
728 gfd = fixedDate + this.getFixedDate (java.util.GregorianCalendar.gcal, year, fieldMask);\r
729 fixedDate = gfd;\r
730 break calculateFixedDate;\r
731 }var millis = (fixedDate - 719163) * 86400000 + timeOfDay;\r
732 var zone = this.getZone ();\r
733 if (this.zoneOffsets == null) {\r
734 this.zoneOffsets =  Clazz.newIntArray (2, 0);\r
735 }var tzMask = fieldMask & (98304);\r
736 if (tzMask != (98304)) {\r
737 if (Clazz.instanceOf (zone, jssun.util.calendar.ZoneInfo)) {\r
738 (zone).getOffsetsByWall (millis, this.zoneOffsets);\r
739 } else {\r
740 var gmtOffset = java.util.Calendar.isFieldSet (fieldMask, 15) ? this.internalGet (15) : zone.getRawOffset ();\r
741 zone.getOffsets (millis - gmtOffset, this.zoneOffsets);\r
742 }}if (tzMask != 0) {\r
743 if (java.util.Calendar.isFieldSet (tzMask, 15)) {\r
744 this.zoneOffsets[0] = this.internalGet (15);\r
745 }if (java.util.Calendar.isFieldSet (tzMask, 16)) {\r
746 this.zoneOffsets[1] = this.internalGet (16);\r
747 }}millis -= this.zoneOffsets[0] + this.zoneOffsets[1];\r
748 this.time = millis;\r
749 var mask = this.computeFields (fieldMask | this.getSetStateFields (), tzMask);\r
750 if (!this.isLenient ()) {\r
751 for (var field = 0; field < 17; field++) {\r
752 if (!this.isExternallySet (field)) {\r
753 continue;\r
754 }if (this.originalFields[field] != this.internalGet (field)) {\r
755 System.arraycopy (this.originalFields, 0, this.fields, 0, this.fields.length);\r
756 throw  new IllegalArgumentException (java.util.Calendar.getFieldName (field));\r
757 }}\r
758 }this.setFieldsNormalized (mask);\r
759 });\r
760 Clazz.defineMethod (c$, "getFixedDate", \r
761  function (cal, year, fieldMask) {\r
762 var month = 0;\r
763 if (java.util.Calendar.isFieldSet (fieldMask, 2)) {\r
764 month = this.internalGet (2);\r
765 if (month > 11) {\r
766 year += Clazz.doubleToInt (month / 12);\r
767 month %= 12;\r
768 } else if (month < 0) {\r
769 var rem =  Clazz.newIntArray (1, 0);\r
770 year += jssun.util.calendar.CalendarUtils.floorDivide (month, 12, rem);\r
771 month = rem[0];\r
772 }}var fixedDate = cal.getFixedDate (year, month + 1, 1, cal === java.util.GregorianCalendar.gcal ? this.gdate : null);\r
773 if (java.util.Calendar.isFieldSet (fieldMask, 2)) {\r
774 if (java.util.Calendar.isFieldSet (fieldMask, 5)) {\r
775 if (this.isSet (5)) {\r
776 fixedDate += this.internalGet (5);\r
777 fixedDate--;\r
778 }} else {\r
779 if (java.util.Calendar.isFieldSet (fieldMask, 4)) {\r
780 var firstDayOfWeek = jssun.util.calendar.AbstractCalendar.getDayOfWeekDateOnOrBefore (fixedDate + 6, this.getFirstDayOfWeek ());\r
781 if ((firstDayOfWeek - fixedDate) >= this.getMinimalDaysInFirstWeek ()) {\r
782 firstDayOfWeek -= 7;\r
783 }if (java.util.Calendar.isFieldSet (fieldMask, 7)) {\r
784 firstDayOfWeek = jssun.util.calendar.AbstractCalendar.getDayOfWeekDateOnOrBefore (firstDayOfWeek + 6, this.internalGet (7));\r
785 }fixedDate = firstDayOfWeek + 7 * (this.internalGet (4) - 1);\r
786 } else {\r
787 var dayOfWeek;\r
788 if (java.util.Calendar.isFieldSet (fieldMask, 7)) {\r
789 dayOfWeek = this.internalGet (7);\r
790 } else {\r
791 dayOfWeek = this.getFirstDayOfWeek ();\r
792 }var dowim;\r
793 if (java.util.Calendar.isFieldSet (fieldMask, 8)) {\r
794 dowim = this.internalGet (8);\r
795 } else {\r
796 dowim = 1;\r
797 }if (dowim >= 0) {\r
798 fixedDate = jssun.util.calendar.AbstractCalendar.getDayOfWeekDateOnOrBefore (fixedDate + (7 * dowim) - 1, dayOfWeek);\r
799 } else {\r
800 var lastDate = this.monthLength (month, year) + (7 * (dowim + 1));\r
801 fixedDate = jssun.util.calendar.AbstractCalendar.getDayOfWeekDateOnOrBefore (fixedDate + lastDate - 1, dayOfWeek);\r
802 }}}} else {\r
803 if (year == this.gregorianCutoverYear && cal === java.util.GregorianCalendar.gcal && fixedDate < this.gregorianCutoverDate && this.gregorianCutoverYear != this.gregorianCutoverYearJulian) {\r
804 fixedDate = this.gregorianCutoverDate;\r
805 }if (java.util.Calendar.isFieldSet (fieldMask, 6)) {\r
806 fixedDate += this.internalGet (6);\r
807 fixedDate--;\r
808 } else {\r
809 var firstDayOfWeek = jssun.util.calendar.AbstractCalendar.getDayOfWeekDateOnOrBefore (fixedDate + 6, this.getFirstDayOfWeek ());\r
810 if ((firstDayOfWeek - fixedDate) >= this.getMinimalDaysInFirstWeek ()) {\r
811 firstDayOfWeek -= 7;\r
812 }if (java.util.Calendar.isFieldSet (fieldMask, 7)) {\r
813 var dayOfWeek = this.internalGet (7);\r
814 if (dayOfWeek != this.getFirstDayOfWeek ()) {\r
815 firstDayOfWeek = jssun.util.calendar.AbstractCalendar.getDayOfWeekDateOnOrBefore (firstDayOfWeek + 6, dayOfWeek);\r
816 }}fixedDate = firstDayOfWeek + 7 * (this.internalGet (3) - 1);\r
817 }}return fixedDate;\r
818 }, "jssun.util.calendar.BaseCalendar,~N,~N");\r
819 Clazz.defineMethod (c$, "getNormalizedCalendar", \r
820  function () {\r
821 var gc;\r
822 if (this.isFullyNormalized ()) {\r
823 gc = this;\r
824 } else {\r
825 gc = this.clone ();\r
826 gc.setLenient (true);\r
827 gc.complete ();\r
828 }return gc;\r
829 });\r
830 Clazz.defineMethod (c$, "getCalendarDate", \r
831  function (fd) {\r
832 var cal = java.util.GregorianCalendar.gcal;\r
833 var d = cal.newCalendarDate (java.util.TimeZone.NO_TIMEZONE);\r
834 cal.getCalendarDateFromFixedDate (d, fd);\r
835 return d;\r
836 }, "~N");\r
837 Clazz.defineMethod (c$, "monthLength", \r
838  function (month, year) {\r
839 return this.isLeapYear (year) ? java.util.GregorianCalendar.LEAP_MONTH_LENGTH[month] : java.util.GregorianCalendar.MONTH_LENGTH[month];\r
840 }, "~N,~N");\r
841 Clazz.defineMethod (c$, "monthLength", \r
842  function (month) {\r
843 var year = this.internalGet (1);\r
844 if (this.internalGetEra () == 0) {\r
845 year = 1 - year;\r
846 }return this.monthLength (month, year);\r
847 }, "~N");\r
848 Clazz.defineMethod (c$, "pinDayOfMonth", \r
849  function () {\r
850 var year = this.internalGet (1);\r
851 var monthLen;\r
852 if (year > this.gregorianCutoverYear || year < this.gregorianCutoverYearJulian) {\r
853 monthLen = this.monthLength (this.internalGet (2));\r
854 } else {\r
855 var gc = this.getNormalizedCalendar ();\r
856 monthLen = gc.getActualMaximum (5);\r
857 }var dom = this.internalGet (5);\r
858 if (dom > monthLen) {\r
859 this.set (5, monthLen);\r
860 }});\r
861 Clazz.defineMethod (c$, "getCurrentFixedDate", \r
862  function () {\r
863 return (this.calsys === java.util.GregorianCalendar.gcal) ? this.cachedFixedDate : this.calsys.getFixedDate (this.cdate);\r
864 });\r
865 c$.getRolledValue = Clazz.defineMethod (c$, "getRolledValue", \r
866  function (value, amount, min, max) {\r
867 var range = max - min + 1;\r
868 amount %= range;\r
869 var n = value + amount;\r
870 if (n > max) {\r
871 n -= range;\r
872 } else if (n < min) {\r
873 n += range;\r
874 }return n;\r
875 }, "~N,~N,~N,~N");\r
876 Clazz.defineMethod (c$, "internalGetEra", \r
877  function () {\r
878 return this.isSet (0) ? this.internalGet (0) : 1;\r
879 });\r
880 Clazz.defineStatics (c$,\r
881 "BC", 0,\r
882 "BCE", 0,\r
883 "AD", 1,\r
884 "CE", 1,\r
885 "EPOCH_OFFSET", 719163,\r
886 "EPOCH_YEAR", 1970,\r
887 "MONTH_LENGTH",  Clazz.newIntArray (-1, [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]),\r
888 "LEAP_MONTH_LENGTH",  Clazz.newIntArray (-1, [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]),\r
889 "ONE_SECOND", 1000,\r
890 "ONE_MINUTE", 60000,\r
891 "ONE_HOUR", 3600000,\r
892 "ONE_DAY", 86400000,\r
893 "MIN_VALUES",  Clazz.newIntArray (-1, [0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, -46800000, 0]),\r
894 "LEAST_MAX_VALUES",  Clazz.newIntArray (-1, [1, 292269054, 11, 52, 4, 28, 365, 7, 4, 1, 11, 23, 59, 59, 999, 50400000, 1200000]),\r
895 "MAX_VALUES",  Clazz.newIntArray (-1, [1, 292278994, 11, 53, 6, 31, 366, 7, 6, 1, 11, 23, 59, 59, 999, 50400000, 7200000]));\r
896 c$.gcal = c$.prototype.gcal = jssun.util.calendar.CalendarSystem.getGregorianCalendar ();\r
897 Clazz.defineStatics (c$,\r
898 "DEFAULT_GREGORIAN_CUTOVER", -12219292800000);\r
899 });\r