Package com.ibm.icu.util

Examples of com.ibm.icu.util.TimeArrayTimeZoneRule


       
        long[] emptytimes = {};
        long[] trtimes1 = {0};
        long[] trtimes2 = {0, 10000000};

        TimeArrayTimeZoneRule t0 = null;
        try {
            // Try to construct TimeArrayTimeZoneRule with null transition times
            t0 = new TimeArrayTimeZoneRule("nulltimes", -3*HOUR, 0,
                    null, DateTimeRule.UTC_TIME);
        } catch (IllegalArgumentException iae) {
            logln("TimeArrayTimeZoneRule constructor throws IllegalArgumentException as expected.");
            t0 = null;
        }
        if (t0 != null) {
            errln("FAIL: TimeArrayTimeZoneRule constructor did not throw IllegalArgumentException for null times");
        }
       
        try {
            // Try to construct TimeArrayTimeZoneRule with empty transition times
            t0 = new TimeArrayTimeZoneRule("nulltimes", -3*HOUR, 0,
                    emptytimes, DateTimeRule.UTC_TIME);
        } catch (IllegalArgumentException iae) {
            logln("TimeArrayTimeZoneRule constructor throws IllegalArgumentException as expected.");
            t0 = null;
        }
        if (t0 != null) {
            errln("FAIL: TimeArrayTimeZoneRule constructor did not throw IllegalArgumentException for empty times");
        }

        TimeArrayTimeZoneRule t1 = new TimeArrayTimeZoneRule("t1", -3*HOUR, 0, trtimes1, DateTimeRule.UTC_TIME);
        TimeArrayTimeZoneRule t2 = new TimeArrayTimeZoneRule("t2", -3*HOUR, 0, trtimes1, DateTimeRule.UTC_TIME);
        TimeArrayTimeZoneRule t3 = new TimeArrayTimeZoneRule("t3", -3*HOUR, 0, trtimes2, DateTimeRule.UTC_TIME);
        TimeArrayTimeZoneRule t4 = new TimeArrayTimeZoneRule("t4", -3*HOUR, 0, trtimes1, DateTimeRule.STANDARD_TIME);
        TimeArrayTimeZoneRule t5 = new TimeArrayTimeZoneRule("t5", -4*HOUR, 1*HOUR, trtimes1, DateTimeRule.WALL_TIME);

        // AnnualTimeZoneRule#getRule
        if (!a1.getRule().equals(a2.getRule())) {
            errln("FAIL: The same DateTimeRule must be returned from AnnualTimeZoneRule a1 and a2");
        }
   
        // AnnualTimeZoneRule#getStartYear
        int startYear = a1.getStartYear();
        if (startYear != 2000) {
            errln("FAIL: The start year of AnnualTimeZoneRule a1 must be 2000 - returned: " + startYear);
        }

        // AnnualTimeZoneRule#getEndYear
        int endYear = a1.getEndYear();
        if (endYear != AnnualTimeZoneRule.MAX_YEAR) {
            errln("FAIL: The start year of AnnualTimeZoneRule a1 must be MAX_YEAR - returned: " + endYear);
        }
        endYear = a3.getEndYear();
        if (endYear != 2010) {
            errln("FAIL: The start year of AnnualTimeZoneRule a3 must be 2010 - returned: " + endYear);
        }
       
        // AnnualTimeZone#getStartInYear
        Date d1 = a1.getStartInYear(2005, -3*HOUR, 0);
        Date d2 = a3.getStartInYear(2005, -3*HOUR, 0);
        if (d1 == null || d2 == null || !d1.equals(d2)) {
            errln("FAIL: AnnualTimeZoneRule#getStartInYear did not work as expected");
        }
        d2 = a3.getStartInYear(2015, -3*HOUR, 0);
        if (d2 != null) {
            errln("FAIL: AnnualTimeZoneRule#getSTartInYear returned non-null date for 2015 which is out of rule range");
        }

        // AnnualTimeZone#getFirstStart
        d1 = a1.getFirstStart(-3*HOUR, 0);
        d2 = a1.getFirstStart(-4*HOUR, 1*HOUR);
        if (d1 == null || d2 == null || !d1.equals(d2)) {
            errln("FAIL: The same start time should be returned by getFirstStart");
        }

        // AnnualTimeZone#getFinalStart
        d1 = a1.getFinalStart(-3*HOUR, 0);
        if (d1 != null) {
            errln("FAIL: Non-null Date is returned by getFinalStart for a1");
        }
        d1 = a1.getStartInYear(2010, -3*HOUR, 0);
        d2 = a3.getFinalStart(-3*HOUR, 0);
        if (d1 == null || d2 == null || !d1.equals(d2)) {
            errln("FAIL: Bad date is returned by getFinalStart");
        }

        // AnnualTimeZone#getNextStart / getPreviousStart
        d1 = a1.getNextStart(time1, -3*HOUR, 0, false);
        if (d1 == null) {
            errln("FAIL: Null Date is returned by getNextStart");
        } else {
            d2 = a1.getPreviousStart(d1.getTime(), -3*HOUR, 0, true);
            if (d2 == null || !d1.equals(d2)) {
                errln("FAIL: Bad Date is returned by getPreviousStart");
            }
        }
        d1 = a3.getNextStart(time2, -3*HOUR, 0, false);
        if (d1 != null) {
            errln("FAIL: getNextStart must return null when no start time is available after the base time");
        }
        d1 = a3.getFinalStart(-3*HOUR, 0);
        d2 = a3.getPreviousStart(time2, -3*HOUR, 0, false);
        if (d1 == null || d2 == null || !d1.equals(d2)) {
            errln("FAIL: getPreviousStart does not match with getFinalStart after the end year");
        }

        // AnnualTimeZone#isEquavalentTo
        if (!a1.isEquivalentTo(a2)) {
            errln("FAIL: AnnualTimeZoneRule a1 is equivalent to a2, but returned false");
        }
        if (a1.isEquivalentTo(a3)) {
            errln("FAIL: AnnualTimeZoneRule a1 is not equivalent to a3, but returned true");
        }
        if (!a1.isEquivalentTo(a1)) {
            errln("FAIL: AnnualTimeZoneRule a1 is equivalent to itself, but returned false");
        }
        if (a1.isEquivalentTo(t1)) {
            errln("FAIL: AnnualTimeZoneRule is not equivalent to TimeArrayTimeZoneRule, but returned true");
        }

        // AnnualTimeZone#isTransitionRule
        if (!a1.isTransitionRule()) {
            errln("FAIL: An AnnualTimeZoneRule is a transition rule, but returned false");
        }

        // AnnualTimeZone#toString
        String str = a1.toString();
        if (str == null || str.length() == 0) {
            errln("FAIL: AnnualTimeZoneRule#toString for a1 returns null or empty string");
        } else {
            logln("AnnualTimeZoneRule a1 : " + str);
        }
        str = a3.toString();
        if (str == null || str.length() == 0) {
            errln("FAIL: AnnualTimeZoneRule#toString for a3 returns null or empty string");
        } else {
            logln("AnnualTimeZoneRule a3 : " + str);
        }

        // InitialTimeZoneRule#isEquivalentRule
        if (!i1.isEquivalentTo(i2)) {
            errln("FAIL: InitialTimeZoneRule i1 is equivalent to i2, but returned false");
        }
        if (i1.isEquivalentTo(i3)) {
            errln("FAIL: InitialTimeZoneRule i1 is not equivalent to i3, but returned true");
        }
        if (i1.isEquivalentTo(a1)) {
            errln("FAIL: An InitialTimeZoneRule is not equivalent to an AnnualTimeZoneRule, but returned true");
        }

        // InitialTimeZoneRule#getFirstStart/getFinalStart/getNextStart/getPreviousStart
        d1 = i1.getFirstStart(0, 0);
        if (d1 != null) {
            errln("FAIL: Non-null Date is returned by InitialTimeZone#getFirstStart");
        }
        d1 = i1.getFinalStart(0, 0);
        if (d1 != null) {
            errln("FAIL: Non-null Date is returned by InitialTimeZone#getFinalStart");
        }
        d1 = i1.getNextStart(time1, 0, 0, false);
        if (d1 != null) {
            errln("FAIL: Non-null Date is returned by InitialTimeZone#getNextStart");
        }
        d1 = i1.getPreviousStart(time1, 0, 0, false);
        if (d1 != null) {
            errln("FAIL: Non-null Date is returned by InitialTimeZone#getPreviousStart");
        }

        // InitialTimeZoneRule#isTransitionRule
        if (i1.isTransitionRule()) {
            errln("FAIL: An InitialTimeZoneRule is not a transition rule, but returned true");
        }

        // InitialTimeZoneRule#toString
        str = i1.toString();
        if (str == null || str.length() == 0) {
            errln("FAIL: InitialTimeZoneRule#toString returns null or empty string");
        } else {
            logln("InitialTimeZoneRule i1 : " + str);
        }
       
       
        // TimeArrayTimeZoneRule#getStartTimes
        long[] times = t1.getStartTimes();
        if (times == null || times.length == 0 || times[0] != 0) {
            errln("FAIL: Bad start times are returned by TimeArrayTimeZoneRule#getStartTimes");
        }

        // TimeArrayTimeZoneRule#getTimeType
        if (t1.getTimeType() != DateTimeRule.UTC_TIME) {
            errln("FAIL: TimeArrayTimeZoneRule t1 uses UTC_TIME, but different type is returned");
        }
        if (t4.getTimeType() != DateTimeRule.STANDARD_TIME) {
            errln("FAIL: TimeArrayTimeZoneRule t4 uses STANDARD_TIME, but different type is returned");
        }
        if (t5.getTimeType() != DateTimeRule.WALL_TIME) {
            errln("FAIL: TimeArrayTimeZoneRule t5 uses WALL_TIME, but different type is returned");
        }

        // TimeArrayTimeZoneRule#getFirstStart/getFinalStart
        d1 = t1.getFirstStart(0, 0);
        if (d1 == null || d1.getTime() != trtimes1[0]) {
            errln("FAIL: Bad first start time returned from TimeArrayTimeZoneRule t1");
        }
        d1 = t1.getFinalStart(0, 0);
        if (d1 == null || d1.getTime() != trtimes1[0]) {
            errln("FAIL: Bad final start time returned from TimeArrayTimeZoneRule t1");
        }
        d1 = t4.getFirstStart(-4*HOUR, 1*HOUR);
        if (d1 == null || (d1.getTime() != trtimes1[0] + 4*HOUR)) {
            errln("FAIL: Bad first start time returned from TimeArrayTimeZoneRule t4");
        }
        d1 = t5.getFirstStart(-4*HOUR, 1*HOUR);
        if (d1 == null || (d1.getTime() != trtimes1[0] + 3*HOUR)) {
            errln("FAIL: Bad first start time returned from TimeArrayTimeZoneRule t5");
        }

        // TimeArrayTimeZoneRule#getNextStart/getPreviousStart
View Full Code Here


                // Adding only transition rules
                rules[idx++] = stzr[1];
                rules[idx++] = stzr[2];
            } else {
                // Create a TimeArrayTimeZoneRule at finalMillis
                rules[idx++] = new TimeArrayTimeZoneRule(getID() + "(STD)", finalZone.getRawOffset(), 0,
                        new long[] {(long)finalMillis}, DateTimeRule.UTC_TIME);               
            }
        }
        return rules;
    }
View Full Code Here

                        raw = typeOffsets[typeIdx*2]*Grego.MILLIS_PER_SECOND;
                        dst = typeOffsets[typeIdx*2 + 1]*Grego.MILLIS_PER_SECOND;
                        if (historicRules == null) {
                            historicRules = new TimeArrayTimeZoneRule[typeCount];
                        }
                        historicRules[typeIdx] = new TimeArrayTimeZoneRule((dst == 0 ? stdName : dstName),
                                raw, dst, startTimes, DateTimeRule.UTC_TIME);
                    }
                }

                // 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])];
View Full Code Here

    private static class TimeArrayTimeZoneRuleHandler implements Handler {
        public Object[] getTestObjects() {
            TimeArrayTimeZoneRule[] rules = new TimeArrayTimeZoneRule[1];
            long[] ttime = new long[] {-631152000000L, 0L, 946684800000L}; /* {1950-1-1, 1970-1-1, 2000-1-1} */
            rules[0] = new TimeArrayTimeZoneRule("Foo", 1*HOUR, 1*HOUR, ttime, DateTimeRule.UTC_TIME);

            return rules;
        }
View Full Code Here

            rules[0] = new TimeArrayTimeZoneRule("Foo", 1*HOUR, 1*HOUR, ttime, DateTimeRule.UTC_TIME);

            return rules;
        }
        public boolean hasSameBehavior(Object a, Object b) {
            TimeArrayTimeZoneRule ra = (TimeArrayTimeZoneRule)a;
            TimeArrayTimeZoneRule rb = (TimeArrayTimeZoneRule)b;

            Date da = ra.getFirstStart(0, 0);
            Date db = rb.getFirstStart(0, 0);
            long t = da.getTime();
            if (da.equals(db)) {
                da = ra.getFinalStart(0, 0);
                db = rb.getFinalStart(0, 0);
                long end = da.getTime();
                if (da.equals(db)) {
                    while (t < end) {
                        da = ra.getNextStart(t, 0, 0, false);
                        db = ra.getNextStart(t, 0, 0, false);
View Full Code Here

        // Adding only transition rules
        rules[idx++] = stzr[1];
        rules[idx++] = stzr[2];
      } else {
        // Create a TimeArrayTimeZoneRule at finalMillis
        rules[idx++] = new TimeArrayTimeZoneRule(getID() + "(STD)", finalZone.getRawOffset(), 0,
            new long[] { (long) finalStartMillis }, DateTimeRule.UTC_TIME);
      }
    }
    return rules;
  }
View Full Code Here

            raw = typeOffsets[typeIdx * 2] * Grego.MILLIS_PER_SECOND;
            dst = typeOffsets[typeIdx * 2 + 1] * Grego.MILLIS_PER_SECOND;
            if (historicRules == null) {
              historicRules = new TimeArrayTimeZoneRule[typeCount];
            }
            historicRules[typeIdx] = new TimeArrayTimeZoneRule((dst == 0 ? stdName : dstName), raw, dst, startTimes,
                DateTimeRule.UTC_TIME);
          }
        }

        // 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])];
View Full Code Here

                // Adding only transition rules
                rules[idx++] = stzr[1];
                rules[idx++] = stzr[2];
            } else {
                // Create a TimeArrayTimeZoneRule at finalMillis
                rules[idx++] = new TimeArrayTimeZoneRule(getID() + "(STD)", finalZone.getRawOffset(), 0,
                        new long[] {(long)finalStartMillis}, DateTimeRule.UTC_TIME);               
            }
        }
        return rules;
    }
View Full Code Here

                        raw = typeOffsets[typeIdx*2]*Grego.MILLIS_PER_SECOND;
                        dst = typeOffsets[typeIdx*2 + 1]*Grego.MILLIS_PER_SECOND;
                        if (historicRules == null) {
                            historicRules = new TimeArrayTimeZoneRule[typeCount];
                        }
                        historicRules[typeIdx] = new TimeArrayTimeZoneRule((dst == 0 ? stdName : dstName),
                                raw, dst, startTimes, DateTimeRule.UTC_TIME);
                    }
                }

                // 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])];
View Full Code Here

                // Adding only transition rules
                rules[idx++] = stzr[1];
                rules[idx++] = stzr[2];
            } else {
                // Create a TimeArrayTimeZoneRule at finalMillis
                rules[idx++] = new TimeArrayTimeZoneRule(getID() + "(STD)", finalZone.getRawOffset(), 0,
                        new long[] {(long)finalMillis}, DateTimeRule.UTC_TIME);               
            }
        }
        return rules;
    }
View Full Code Here

TOP

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

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.