Package com.ibm.icu.util

Examples of com.ibm.icu.util.TimeZoneTransition


                if (from.getName().equals(to.getName()) && from.getRawOffset() == to.getRawOffset()
                        && from.getDSTSavings() == to.getDSTSavings()) {
                    return getNextTransition(startTime, false);
                }

                return new TimeZoneTransition(startTime, from, to);
            }
        }
        return null;
    }
View Full Code Here


                if (from.getName().equals(to.getName()) && from.getRawOffset() == to.getRawOffset()
                        && from.getDSTSavings() == to.getDSTSavings()) {
                    return getPreviousTransition(startTime, false);
                }

                return new TimeZoneTransition(startTime, from, to);
            }
        }
        return null;
    }
View Full Code Here

                    }
                }

                // Create initial transition
                typeIdx = getInt(typeData[firstTZTransitionIdx]);
                firstTZTransition = new TimeZoneTransition(((long)transitionTimes[firstTZTransitionIdx])*Grego.MILLIS_PER_SECOND,
                        initialRule, historicRules[typeIdx]);
               
            }
        }

        if (initialRule == null) {
            // No historic transitions
            raw = typeOffsets[0]*Grego.MILLIS_PER_SECOND;
            dst = typeOffsets[1]*Grego.MILLIS_PER_SECOND;
            initialRule = new InitialTimeZoneRule((dst == 0 ? stdName : dstName), raw, dst);
        }

        if (finalZone != null) {
            // Get the first occurrence of final rule starts
            long startTime = (long)finalMillis;
            TimeZoneRule firstFinalRule;
            if (finalZone.useDaylightTime()) {
                /*
                 * Note: When an OlsonTimeZone is constructed, we should set the final year
                 * as the start year of finalZone.  However, the boundary condition used for
                 * getting offset from finalZone has some problems.  So setting the start year
                 * in the finalZone will cause a problem.  For now, we do not set the valid
                 * start year when the construction time and create a clone and set the
                 * start year when extracting rules.
                 */
                finalZoneWithStartYear = (SimpleTimeZone)finalZone.clone();
                // finalYear is 1 year before the actual final year.
                // See the comment in the construction method.
                finalZoneWithStartYear.setStartYear(finalYear + 1);

                TimeZoneTransition tzt = finalZoneWithStartYear.getNextTransition(startTime, false);
                firstFinalRule  = tzt.getTo();
                startTime = tzt.getTime();
            } else {
                finalZoneWithStartYear = finalZone;
                firstFinalRule = new TimeArrayTimeZoneRule(finalZone.getID(),
                        finalZone.getRawOffset(), 0, new long[] {startTime}, DateTimeRule.UTC_TIME);
            }
            TimeZoneRule prevRule = null;
            if (transitionCount > 0) {
                prevRule = historicRules[getInt(typeData[transitionCount - 1])];
            }
            if (prevRule == null) {
                // No historic transitions, but only finalZone available
                prevRule = initialRule;
            }
            firstFinalTZTransition = new TimeZoneTransition(startTime, prevRule, firstFinalRule);
        }

        transitionRulesInitialized = true;
    }
View Full Code Here

                    BasicTimeZone btz = (BasicTimeZone)TimeZone.getTimeZone(ids[zidx], TimeZone.TIMEZONE_ICU);
                    TimeZone tz = TimeZone.getTimeZone(ids[zidx]);
                    sdf.setTimeZone(tz);

                    long t = START_TIME;
                    TimeZoneTransition tzt = null;
                    boolean middle = true;
                    while (t < END_TIME) {
                        if (tzt == null) {
                            testTimes[0] = t;
                            expectedRoundTrip[0] = true;
                            testLen = 1;
                        } else {
                            int fromOffset = tzt.getFrom().getRawOffset() + tzt.getFrom().getDSTSavings();
                            int toOffset = tzt.getTo().getRawOffset() + tzt.getTo().getDSTSavings();
                            int delta = toOffset - fromOffset;
                            if (delta < 0) {
                                boolean isDstDecession = tzt.getFrom().getDSTSavings() > 0 && tzt.getTo().getDSTSavings() == 0;
                                testTimes[0] = t + delta - 1;
                                expectedRoundTrip[0] = true;
                                testTimes[1] = t + delta;
                                expectedRoundTrip[1] = isDstDecession ?
                                        !AMBIGUOUS_DST_DECESSION[patidx] : !AMBIGUOUS_NEGATIVE_SHIFT[patidx];
                                testTimes[2] = t - 1;
                                expectedRoundTrip[2] = isDstDecession ?
                                        !AMBIGUOUS_DST_DECESSION[patidx] : !AMBIGUOUS_NEGATIVE_SHIFT[patidx];
                                testTimes[3] = t;
                                expectedRoundTrip[3] = true;
                                testLen = 4;
                            } else {
                                testTimes[0] = t - 1;
                                expectedRoundTrip[0] = true;
                                testTimes[1] = t;
                                expectedRoundTrip[1] = true;
                                testLen = 2;
                            }
                        }
                        for (int testidx = 0; testidx < testLen; testidx++) {
                            testCounts++;
                            timer = System.currentTimeMillis();
                            String text = sdf.format(new Date(testTimes[testidx]));
                            try {
                                Date parsedDate = sdf.parse(text);
                                long restime = parsedDate.getTime();
                                if (restime != testTimes[testidx]) {
                                    StringBuffer msg = new StringBuffer();
                                    msg.append("Time round trip failed for ")
                                        .append("tzid=").append(ids[zidx])
                                        .append(", locale=").append(LOCALES[locidx])
                                        .append(", pattern=").append(PATTERNS[patidx])
                                        .append(", text=").append(text)
                                        .append(", gmt=").append(sdfGMT.format(new Date(testTimes[testidx])))
                                        .append(", time=").append(testTimes[testidx])
                                        .append(", restime=").append(restime)
                                        .append(", diff=").append(restime - testTimes[testidx]);
                                    if (expectedRoundTrip[testidx]) {
                                        errln("FAIL: " + msg.toString());
                                    } else if (REALLY_VERBOSE) {
                                        logln(msg.toString());
                                    }
                                }
                            } catch (ParseException pe) {
                                errln("FAIL: " + pe.getMessage());
                            }
                            times[patidx] += System.currentTimeMillis() - timer;
                        }
                        tzt = btz.getNextTransition(t, false);
                        if (tzt == null) {
                            break;
                        }
                        if (middle) {
                            // Test the date in the middle of two transitions.
                            t += (tzt.getTime() - t)/2;
                            middle = false;
                            tzt = null;
                        } else {
                            t = tzt.getTime();
                        }
                    }
                }
            }
        }
View Full Code Here

                if (cal.get(Calendar.DST_OFFSET) == 0) {
                    useStandard = true;
                    // Check if the zone actually uses daylight saving time around the time
                    if (tz instanceof BasicTimeZone) {
                        BasicTimeZone btz = (BasicTimeZone)tz;
                        TimeZoneTransition before = btz.getPreviousTransition(time, true);
                        if (before != null
                                && (time - before.getTime() < DST_CHECK_RANGE)
                                && before.getFrom().getDSTSavings() != 0) {
                            useStandard = false;
                        } else {
                            TimeZoneTransition after = btz.getNextTransition(time, false);
                            if (after != null
                                    && (after.getTime() - time < DST_CHECK_RANGE)
                                    && after.getTo().getDSTSavings() != 0) {
                                useStandard = false;
                            }
                        }
                    } else {
                        // If not BasicTimeZone... only if the instance is not an ICU's implementation.
View Full Code Here

      if (offsets[1] == 0) {
        useStandard = true;
        // Check if the zone actually uses daylight saving time around the time
        if (tz instanceof BasicTimeZone) {
          BasicTimeZone btz = (BasicTimeZone) tz;
          TimeZoneTransition before = btz.getPreviousTransition(date, true);
          if (before != null && (date - before.getTime() < DST_CHECK_RANGE) && before.getFrom().getDSTSavings() != 0) {
            useStandard = false;
          } else {
            TimeZoneTransition after = btz.getNextTransition(date, false);
            if (after != null && (after.getTime() - date < DST_CHECK_RANGE) && after.getTo().getDSTSavings() != 0) {
              useStandard = false;
            }
          }
        } else {
          // If not BasicTimeZone... only if the instance is not an ICU's implementation.
View Full Code Here

        if (currentRules.length != 3) {
          // DST was observed at the beginning of this year, so useDaylightTime
          // returned true.  getSimpleTimeZoneRulesNear requires at least one
          // future transition for making a pair of rules.  This implementation
          // rolls back the time before the latest offset transition.
          TimeZoneTransition tzt = getPreviousTransition(current, false);
          if (tzt != null) {
            currentRules = getSimpleTimeZoneRulesNear(tzt.getTime() - 1);
          }
        }
        if (currentRules.length == 3 && (currentRules[1] instanceof AnnualTimeZoneRule)
            && (currentRules[2] instanceof AnnualTimeZoneRule)) {
          // A pair of AnnualTimeZoneRule
View Full Code Here

        if (from.getName().equals(to.getName()) && from.getRawOffset() == to.getRawOffset()
            && from.getDSTSavings() == to.getDSTSavings()) {
          return getNextTransition(startTime, false);
        }

        return new TimeZoneTransition(startTime, from, to);
      }
    }
    return null;
  }
View Full Code Here

        if (from.getName().equals(to.getName()) && from.getRawOffset() == to.getRawOffset()
            && from.getDSTSavings() == to.getDSTSavings()) {
          return getPreviousTransition(startTime, false);
        }

        return new TimeZoneTransition(startTime, from, to);
      }
    }
    return null;
  }
View Full Code Here

          }
        }

        // Create initial transition
        typeIdx = getInt(typeMapData[firstTZTransitionIdx]);
        firstTZTransition = new TimeZoneTransition(transitionTimes64[firstTZTransitionIdx] * Grego.MILLIS_PER_SECOND, initialRule,
            historicRules[typeIdx]);

      }
    }

    if (finalZone != null) {
      // Get the first occurrence of final rule starts
      long startTime = (long) finalStartMillis;
      TimeZoneRule firstFinalRule;
      if (finalZone.useDaylightTime()) {
        /*
         * Note: When an OlsonTimeZone is constructed, we should set the final year
         * as the start year of finalZone.  However, the boundary condition used for
         * getting offset from finalZone has some problems.  So setting the start year
         * in the finalZone will cause a problem.  For now, we do not set the valid
         * start year when the construction time and create a clone and set the
         * start year when extracting rules.
         */
        finalZoneWithStartYear = (SimpleTimeZone) finalZone.clone();
        finalZoneWithStartYear.setStartYear(finalStartYear);

        TimeZoneTransition tzt = finalZoneWithStartYear.getNextTransition(startTime, false);
        firstFinalRule = tzt.getTo();
        startTime = tzt.getTime();
      } else {
        finalZoneWithStartYear = finalZone;
        firstFinalRule = new TimeArrayTimeZoneRule(finalZone.getID(), finalZone.getRawOffset(), 0, new long[] { startTime },
            DateTimeRule.UTC_TIME);
      }
      TimeZoneRule prevRule = null;
      if (transitionCount > 0) {
        prevRule = historicRules[getInt(typeMapData[transitionCount - 1])];
      }
      if (prevRule == null) {
        // No historic transitions, but only finalZone available
        prevRule = initialRule;
      }
      firstFinalTZTransition = new TimeZoneTransition(startTime, prevRule, firstFinalRule);
    }

    transitionRulesInitialized = true;
  }
View Full Code Here

TOP

Related Classes of com.ibm.icu.util.TimeZoneTransition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.