256 if (offsets != null) {
257 offsets[0] = offset;
258 offsets[1] = 0;
259 }
260 return offset;
261 }
262
263 if (index < transitions.length) {
264 long val = transitions[index];
265 int offset = this.offsets[(int)(val & OFFSET_MASK)] + rawOffsetDiff;
266 if (offsets != null) {
267 int dst = (int)((val >>> DST_NSHIFT) & 0xfL);
268 int save = (dst == 0) ? 0 : this.offsets[dst];
269 offsets[0] = offset - save;
270 offsets[1] = save;
271 }
272 return offset;
273 }
274
275 // beyond the transitions, delegate to SimpleTimeZone if there
276 // is a rule; otherwise, return rawOffset.
277 SimpleTimeZone tz = getLastRule();
278 if (tz != null) {
279 int rawoffset = tz.getRawOffset();
280 long msec = date;
281 if (type != UTC_TIME) {
282 msec -= rawOffset;
283 }
284 int dstoffset = tz.getOffset(msec) - rawOffset;
285
286 // Check if it's in a standard-to-daylight transition.
287 if (dstoffset > 0 && tz.getOffset(msec - dstoffset) == rawoffset) {
288 dstoffset = 0;
289 }
290
291 if (offsets != null) {
292 offsets[0] = rawoffset;
293 offsets[1] = dstoffset;
294 }
295 return rawoffset + dstoffset;
296 }
297 int offset = getLastRawOffset();
298 if (offsets != null) {
299 offsets[0] = offset;
300 offsets[1] = 0;
301 }
302 return offset;
303 }
304
305 private int getTransitionIndex(long date, int type) {
306 int low = 0;
307 int high = transitions.length - 1;
308
309 while (low <= high) {
310 int mid = (low + high) / 2;
311 long val = transitions[mid];
312 long midVal = val >> TRANSITION_NSHIFT; // sign extended
313 if (type != UTC_TIME) {
314 midVal += offsets[(int)(val & OFFSET_MASK)]; // wall time
315 }
316 if (type == STANDARD_TIME) {
317 int dstIndex = (int)((val >>> DST_NSHIFT) & 0xfL);
318 if (dstIndex != 0) {
319 midVal -= offsets[dstIndex]; // make it standard time
320 }
321 }
322
323 if (midVal < date) {
485 return false;
486 }
487
488 long utc = date.getTime() - rawOffsetDiff;
489 int index = getTransitionIndex(utc, UTC_TIME);
490
491 // before transitions in the transition table
492 if (index < 0) {
493 return false;
494 }
495
496 // the time is in the table range.
497 if (index < transitions.length) {
498 return (transitions[index] & DST_MASK) != 0;
499 }
500
501 // beyond the transition table
502 SimpleTimeZone tz = getLastRule();
503 if (tz != null) {
504 return tz.inDaylightTime(date);
505 }
506 return false;
507 }
508
509 /**
510 * Returns the amount of time in milliseconds that the clock is advanced
511 * during daylight saving time is in effect in its last daylight saving time rule.
512 *
513 * @return the number of milliseconds the time is advanced with respect to
514 * standard time when daylight saving time is in effect.
515 */
516 public int getDSTSavings() {
517 return dstSavings;
518 }
519
520 // /**
521 // * @return the last year in the transition table or -1 if this
522 // * time zone doesn't observe any daylight saving time.
523 // */
524 // public int getMaxTransitionYear() {
525 // if (transitions == null) {
526 // return -1;
|
256 if (offsets != null) {
257 offsets[0] = offset;
258 offsets[1] = 0;
259 }
260 return offset;
261 }
262
263 if (index < transitions.length) {
264 long val = transitions[index];
265 int offset = this.offsets[(int)(val & OFFSET_MASK)] + rawOffsetDiff;
266 if (offsets != null) {
267 int dst = (int)((val >>> DST_NSHIFT) & 0xfL);
268 int save = (dst == 0) ? 0 : this.offsets[dst];
269 offsets[0] = offset - save;
270 offsets[1] = save;
271 }
272 return offset;
273 }
274
275 // beyond the transitions, delegate to SimpleTimeZone if there
276 // is a rule; otherwise, return the offset of the last transition.
277 SimpleTimeZone tz = getLastRule();
278 if (tz != null) {
279 int rawoffset = tz.getRawOffset();
280 long msec = date;
281 if (type != UTC_TIME) {
282 msec -= rawOffset;
283 }
284 int dstoffset = tz.getOffset(msec) - rawOffset;
285
286 // Check if it's in a standard-to-daylight transition.
287 if (dstoffset > 0 && tz.getOffset(msec - dstoffset) == rawoffset) {
288 dstoffset = 0;
289 }
290
291 if (offsets != null) {
292 offsets[0] = rawoffset;
293 offsets[1] = dstoffset;
294 }
295 return rawoffset + dstoffset;
296 } else {
297 // use the last transition
298 long val = transitions[transitions.length - 1];
299 int offset = this.offsets[(int)(val & OFFSET_MASK)] + rawOffsetDiff;
300 if (offsets != null) {
301 int dst = (int)((val >>> DST_NSHIFT) & 0xfL);
302 int save = (dst == 0) ? 0 : this.offsets[dst];
303 offsets[0] = offset - save;
304 offsets[1] = save;
305 }
306 return offset;
307 }
308 }
309
310 private int getTransitionIndex(long date, int type) {
311 int low = 0;
312 int high = transitions.length - 1;
313
314 while (low <= high) {
315 int mid = (low + high) / 2;
316 long val = transitions[mid];
317 long midVal = val >> TRANSITION_NSHIFT; // sign extended
318 if (type != UTC_TIME) {
319 midVal += offsets[(int)(val & OFFSET_MASK)]; // wall time
320 }
321 if (type == STANDARD_TIME) {
322 int dstIndex = (int)((val >>> DST_NSHIFT) & 0xfL);
323 if (dstIndex != 0) {
324 midVal -= offsets[dstIndex]; // make it standard time
325 }
326 }
327
328 if (midVal < date) {
490 return false;
491 }
492
493 long utc = date.getTime() - rawOffsetDiff;
494 int index = getTransitionIndex(utc, UTC_TIME);
495
496 // before transitions in the transition table
497 if (index < 0) {
498 return false;
499 }
500
501 // the time is in the table range.
502 if (index < transitions.length) {
503 return (transitions[index] & DST_MASK) != 0;
504 }
505
506 // beyond the transition table
507 SimpleTimeZone tz = getLastRule();
508 if (tz != null) {
509 return tz.inDaylightTime(date);
510 } else {
511 // use the last transition
512 return (transitions[transitions.length - 1] & DST_MASK) != 0;
513 }
514 }
515
516 /**
517 * Returns the amount of time in milliseconds that the clock is advanced
518 * during daylight saving time is in effect in its last daylight saving time rule.
519 *
520 * @return the number of milliseconds the time is advanced with respect to
521 * standard time when daylight saving time is in effect.
522 */
523 public int getDSTSavings() {
524 return dstSavings;
525 }
526
527 // /**
528 // * @return the last year in the transition table or -1 if this
529 // * time zone doesn't observe any daylight saving time.
530 // */
531 // public int getMaxTransitionYear() {
532 // if (transitions == null) {
533 // return -1;
|