Package com.ibm.icu.util

Examples of com.ibm.icu.util.DateTimeRule


                Calendar.SEPTEMBER, -30, -Calendar.SATURDAY, 1*HOUR, SimpleTimeZone.WALL_TIME,
                Calendar.FEBRUARY, 2, Calendar.SUNDAY, 1*HOUR, SimpleTimeZone.WALL_TIME,
                1*HOUR);


        DateTimeRule dtr;
        AnnualTimeZoneRule atzr;
        final int STARTYEAR = 2000;

        InitialTimeZoneRule ir = new InitialTimeZoneRule(
                "RBTZ_Initial", // Initial time Name
                -1*HOUR,        // Raw offset
                1*HOUR);        // DST saving amount
       
        // RBTZ
        RuleBasedTimeZone rbtz1 = new RuleBasedTimeZone("RBTZ1", ir);
        dtr = new DateTimeRule(Calendar.SEPTEMBER, 30, Calendar.SATURDAY, false,
                1*HOUR, DateTimeRule.WALL_TIME); // SUN<=30 in September, at 1AM wall time
        atzr = new AnnualTimeZoneRule("RBTZ_DST1",
                -1*HOUR /* rawOffset */, 1*HOUR /* dstSavings */, dtr,
                STARTYEAR, AnnualTimeZoneRule.MAX_YEAR);
        rbtz1.addTransitionRule(atzr);
        dtr = new DateTimeRule(Calendar.FEBRUARY, 2, Calendar.SUNDAY,
                1*HOUR, DateTimeRule.WALL_TIME); // 2nd Sunday in February, at 1AM wall time
        atzr = new AnnualTimeZoneRule("RBTZ_STD1",
                -1*HOUR /* rawOffset */, 0 /* dstSavings */, dtr,
                STARTYEAR, AnnualTimeZoneRule.MAX_YEAR);
        rbtz1.addTransitionRule(atzr);

        // Equivalent, but different date rule type
        RuleBasedTimeZone rbtz2 = new RuleBasedTimeZone("RBTZ2", ir);
        dtr = new DateTimeRule(Calendar.SEPTEMBER, -1, Calendar.SATURDAY,
                1*HOUR, DateTimeRule.WALL_TIME); // Last Sunday in September at 1AM wall time
        atzr = new AnnualTimeZoneRule("RBTZ_DST2", -1*HOUR, 1*HOUR, dtr, STARTYEAR, AnnualTimeZoneRule.MAX_YEAR);
        rbtz2.addTransitionRule(atzr);
        dtr = new DateTimeRule(Calendar.FEBRUARY, 8, Calendar.SUNDAY, true,
                1*HOUR, DateTimeRule.WALL_TIME); // SUN>=8 in February, at 1AM wall time
        atzr = new AnnualTimeZoneRule("RBTZ_STD2", -1*HOUR, 0, dtr, STARTYEAR, AnnualTimeZoneRule.MAX_YEAR);
        rbtz2.addTransitionRule(atzr);

        // Equivalent, but different time rule type
        RuleBasedTimeZone rbtz3 = new RuleBasedTimeZone("RBTZ3", ir);
        dtr = new DateTimeRule(Calendar.SEPTEMBER, 30, Calendar.SATURDAY, false,
                2*HOUR, DateTimeRule.UTC_TIME);
        atzr = new AnnualTimeZoneRule("RBTZ_DST3", -1*HOUR, 1*HOUR, dtr, STARTYEAR, AnnualTimeZoneRule.MAX_YEAR);
        rbtz3.addTransitionRule(atzr);
        dtr = new DateTimeRule(Calendar.FEBRUARY, 2, Calendar.SUNDAY,
                0*HOUR, DateTimeRule.STANDARD_TIME);
        atzr = new AnnualTimeZoneRule("RBTZ_STD3", -1*HOUR, 0, dtr, STARTYEAR, AnnualTimeZoneRule.MAX_YEAR);
        rbtz3.addTransitionRule(atzr);

        // Check equivalency for 10 years
        long start = getUTCMillis(STARTYEAR, Calendar.JANUARY, 1);
        long until = getUTCMillis(STARTYEAR + 10, Calendar.JANUARY, 1);

        if (!(stz.hasEquivalentTransitions(rbtz1, start, until))) {
            errln("FAIL: rbtz1 must be equivalent to the SimpleTimeZone in the time range.");
        }
        if (!(stz.hasEquivalentTransitions(rbtz2, start, until))) {
            errln("FAIL: rbtz2 must be equivalent to the SimpleTimeZone in the time range.");
        }
        if (!(stz.hasEquivalentTransitions(rbtz3, start, until))) {
            errln("FAIL: rbtz3 must be equivalent to the SimpleTimeZone in the time range.");
        }

        // hasSameRules
        if (rbtz1.hasSameRules(rbtz2)) {
            errln("FAIL: rbtz1 and rbtz2 have different rules, but returned true.");
        }
        if (rbtz1.hasSameRules(rbtz3)) {
            errln("FAIL: rbtz1 and rbtz3 have different rules, but returned true.");
        }
        RuleBasedTimeZone rbtz1c = (RuleBasedTimeZone)rbtz1.clone();
        if (!rbtz1.hasSameRules(rbtz1c)) {
            errln("FAIL: Cloned RuleBasedTimeZone must have the same rules with the original.");
        }

        // getOffset
        GregorianCalendar cal = new GregorianCalendar();
        int[] offsets = new int[2];
        int offset;
        boolean dst;

        cal.setTimeZone(rbtz1);
        cal.clear();

        // Jan 1, 1000 BC
        cal.set(Calendar.ERA, GregorianCalendar.BC);
        cal.set(1000, Calendar.JANUARY, 1);

        offset = rbtz1.getOffset(cal.get(Calendar.ERA), cal.get(Calendar.YEAR), cal.get(Calendar.MONTH),
                cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.DAY_OF_WEEK), cal.get(Calendar.MILLISECONDS_IN_DAY));
        if (offset != 0) {
            errln("FAIL: Invalid time zone offset: " + offset + " /expected: 0");
        }
        dst = rbtz1.inDaylightTime(cal.getTime());
        if (!dst) {
            errln("FAIL: Invalid daylight saving time");
        }
        rbtz1.getOffset(cal.getTimeInMillis(), true, offsets);
        if (offsets[0] != -3600000) {
            errln("FAIL: Invalid time zone raw offset: " + offsets[0] + " /expected: -3600000");
        }
        if (offsets[1] != 3600000) {           
            errln("FAIL: Invalid DST amount: " + offsets[1] + " /expected: 3600000");
        }

        // July 1, 2000, AD
        cal.set(Calendar.ERA, GregorianCalendar.AD);
        cal.set(2000, Calendar.JULY, 1);

        offset = rbtz1.getOffset(cal.get(Calendar.ERA), cal.get(Calendar.YEAR), cal.get(Calendar.MONTH),
                cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.DAY_OF_WEEK), cal.get(Calendar.MILLISECONDS_IN_DAY));
        if (offset != -3600000) {
            errln("FAIL: Invalid time zone offset: " + offset + " /expected: -3600000");
        }
        dst = rbtz1.inDaylightTime(cal.getTime());
        if (dst) {
            errln("FAIL: Invalid daylight saving time");
        }
        rbtz1.getOffset(cal.getTimeInMillis(), true, offsets);
        if (offsets[0] != -3600000) {
            errln("FAIL: Invalid time zone raw offset: " + offsets[0] + " /expected: -3600000");
        }
        if (offsets[1] != 0) {           
            errln("FAIL: Invalid DST amount: " + offsets[1] + " /expected: 0");
        }

        // July 1, 2000, AD

        // Try to add 3rd final rule
        dtr = new DateTimeRule(Calendar.OCTOBER, 15, 1*HOUR, DateTimeRule.WALL_TIME);
        atzr = new AnnualTimeZoneRule("3RD_ATZ", -1*HOUR, 2*HOUR, dtr, STARTYEAR, AnnualTimeZoneRule.MAX_YEAR);
        boolean bException = false;
        try {
            rbtz1.addTransitionRule(atzr);
        } catch (IllegalStateException ise) {
View Full Code Here


        //RBTZ
        InitialTimeZoneRule ir = new InitialTimeZoneRule("EST", -5*HOUR, 0);
        RuleBasedTimeZone rbtz = new RuleBasedTimeZone("EST5EDT", ir);

        DateTimeRule dtr;
        AnnualTimeZoneRule tzr;

        // Standard time
        dtr = new DateTimeRule(Calendar.OCTOBER, -1, Calendar.SUNDAY,
                2*HOUR, DateTimeRule.WALL_TIME);    // Last Sunday in October, at 2AM wall time
        tzr = new AnnualTimeZoneRule("EST", -5*HOUR /* rawOffset */, 0 /* dstSavings */, dtr, 1967, 2006);
        rbtz.addTransitionRule(tzr);

        dtr = new DateTimeRule(Calendar.NOVEMBER, 1, Calendar.SUNDAY,
                true, 2*HOUR, DateTimeRule.WALL_TIME)// SUN>=1 in November, at 2AM wall time
        tzr = new AnnualTimeZoneRule("EST", -5*HOUR, 0, dtr, 2007, AnnualTimeZoneRule.MAX_YEAR);
        rbtz.addTransitionRule(tzr);

        // Daylight saving time
        dtr = new DateTimeRule(Calendar.APRIL, -1, Calendar.SUNDAY,
                2*HOUR, DateTimeRule.WALL_TIME);    // Last Sunday in April, at 2AM wall time
        tzr = new AnnualTimeZoneRule("EDT", -5*HOUR, 1*HOUR, dtr, 1967, 1973);
        rbtz.addTransitionRule(tzr);

        dtr = new DateTimeRule(Calendar.JANUARY, 6,
                2*HOUR, DateTimeRule.WALL_TIME);    // January 6, at 2AM wall time
        tzr = new AnnualTimeZoneRule("EDT", -5*HOUR, 1*HOUR, dtr, 1974, 1974);
        rbtz.addTransitionRule(tzr);
       
        dtr = new DateTimeRule(Calendar.FEBRUARY, 23,
                2*HOUR, DateTimeRule.WALL_TIME);    // February 23, at 2AM wall time
        tzr = new AnnualTimeZoneRule("EDT", -5*HOUR, 1*HOUR, dtr, 1975, 1975);
        rbtz.addTransitionRule(tzr);

        dtr = new DateTimeRule(Calendar.APRIL, -1, Calendar.SUNDAY,
                2*HOUR, DateTimeRule.WALL_TIME);    // Last Sunday in April, at 2AM wall time
        tzr = new AnnualTimeZoneRule("EDT", -5*HOUR, 1*HOUR, dtr, 1976, 1986);
        rbtz.addTransitionRule(tzr);

        dtr = new DateTimeRule(Calendar.APRIL, 1, Calendar.SUNDAY,
                true, 2*HOUR, DateTimeRule.WALL_TIME)// SUN>=1 in April, at 2AM wall time
        tzr = new AnnualTimeZoneRule("EDT", -5*HOUR, 1*HOUR, dtr, 1987, 2006);
        rbtz.addTransitionRule(tzr);

        dtr = new DateTimeRule(Calendar.MARCH, 8, Calendar.SUNDAY,
                true, 2*HOUR, DateTimeRule.WALL_TIME)// SUN>=8 in March, at 2AM wall time
        tzr = new AnnualTimeZoneRule("EDT", -5*HOUR, 1*HOUR, dtr, 2007, AnnualTimeZoneRule.MAX_YEAR);
        rbtz.addTransitionRule(tzr);

        // hasEquivalentTransitions
View Full Code Here

                                || !(rules[1] instanceof AnnualTimeZoneRule)
                                || !(rules[2] instanceof AnnualTimeZoneRule)) {
                            errln("FAIL: Unexpected rule object type is returned for " + tzids[i] + " at " + time);
                        }
                        for (int idx = 1; idx <= 2; idx++) {
                            DateTimeRule dtr = ((AnnualTimeZoneRule)rules[idx]).getRule();
                            if (dtr.getTimeRuleType() != DateTimeRule.WALL_TIME) {
                                errln("FAIL: WALL_TIME is not used as the time rule in the time zone rule(" + idx + ") for " + tzids[i] + " at " + time);
                            }
                            if (dtr.getDateRuleType() != DateTimeRule.DOW) {
                                errln("FAIL: DOW is not used as the date rule in the time zone rule(" + idx + ") for " + tzids[i] + " at " + time);
                            }
                        }
                    } else {
                        errln("FAIL: Unexpected number of rules returned for " + tzids[i] + " at " + time);
View Full Code Here

    public void TestTimeZoneRuleCoverage() {
        long time1 = getUTCMillis(2005, Calendar.JULY, 4);
        long time2 = getUTCMillis(2015, Calendar.JULY, 4);
        long time3 = getUTCMillis(1950, Calendar.JULY, 4);

        DateTimeRule dtr1 = new DateTimeRule(Calendar.FEBRUARY, 29, Calendar.SUNDAY, false,
                3*HOUR, DateTimeRule.WALL_TIME); // Last Sunday on or before Feb 29, at 3 AM, wall time
        DateTimeRule dtr2 = new DateTimeRule(Calendar.MARCH, 11, 2*HOUR,
                DateTimeRule.STANDARD_TIME); // Mar 11, at 2 AM, standard time
        DateTimeRule dtr3 = new DateTimeRule(Calendar.OCTOBER, -1, Calendar.SATURDAY,
                6*HOUR, DateTimeRule.UTC_TIME); //Last Saturday in Oct, at 6 AM, UTC
        DateTimeRule dtr4 = new DateTimeRule(Calendar.MARCH, 8, Calendar.SUNDAY, true,
                2*HOUR, DateTimeRule.WALL_TIME); // First Sunday on or after Mar 8, at 2 AM, wall time

        AnnualTimeZoneRule a1 = new AnnualTimeZoneRule("a1", -3*HOUR, 1*HOUR, dtr1,
                2000, AnnualTimeZoneRule.MAX_YEAR);
        AnnualTimeZoneRule a2 = new AnnualTimeZoneRule("a2", -3*HOUR, 1*HOUR, dtr1,
                2000, AnnualTimeZoneRule.MAX_YEAR);
        AnnualTimeZoneRule a3 = new AnnualTimeZoneRule("a3", -3*HOUR, 1*HOUR, dtr1,
                2000, 2010);
       
        InitialTimeZoneRule i1 = new InitialTimeZoneRule("i1", -3*HOUR, 0);
        InitialTimeZoneRule i2 = new InitialTimeZoneRule("i2", -3*HOUR, 0);
        InitialTimeZoneRule i3 = new InitialTimeZoneRule("i3", -3*HOUR, 1*HOUR);
       
        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
        d1 = t3.getNextStart(time1, -3*HOUR, 1*HOUR, false);
        if (d1 != null) {
            errln("FAIL: Non-null Date is returned by getNextStart after the final transition for t3");
        }
        d1 = t3.getPreviousStart(time1, -3*HOUR, 1*HOUR, false);
        if (d1 == null || d1.getTime() != trtimes2[1]) {
            errln("FAIL: Bad start time returned by getPreviousStart for t3");
        } else {
            d2 = t3.getPreviousStart(d1.getTime(), -3*HOUR, 1*HOUR, false);
            if (d2 == null || d2.getTime() != trtimes2[0]) {
                errln("FAIL: Bad start time returned by getPreviousStart for t3");
            }
        }
        d1 = t3.getPreviousStart(time3, -3*HOUR, 1*HOUR, false); //time3 - year 1950, no result expected
        if (d1 != null) {
            errln("FAIL: Non-null Date is returned by getPrevoousStart for t3");
        }

        // TimeArrayTimeZoneRule#isEquivalentTo
        if (!t1.isEquivalentTo(t2)) {
            errln("FAIL: TimeArrayTimeZoneRule t1 is equivalent to t2, but returned false");
        }
        if (t1.isEquivalentTo(t3)) {
            errln("FAIL: TimeArrayTimeZoneRule t1 is not equivalent to t3, but returned true");
        }
        if (t1.isEquivalentTo(t4)) {
            errln("FAIL: TimeArrayTimeZoneRule t1 is not equivalent to t4, but returned true");
        }
        if (t1.isEquivalentTo(a1)) {
            errln("FAIL: TimeArrayTimeZoneRule is not equivalent to AnnualTimeZoneRule, but returned true");
        }

        // TimeArrayTimeZoneRule#isTransitionRule
        if (!t1.isTransitionRule()) {
            errln("FAIL: A TimeArrayTimeZoneRule is a transition rule, but returned false");
        }

        // TimeArrayTimeZoneRule#toString
        str = t3.toString();
        if (str == null || str.length() == 0) {
            errln("FAIL: TimeArrayTimeZoneRule#toString returns null or empty string");
        } else {
            logln("TimeArrayTimeZoneRule t3 : " + str);
        }

        // DateTimeRule#toString
        str = dtr1.toString();
        if (str == null || str.length() == 0) {
            errln("FAIL: DateTimeRule#toString for dtr1 returns null or empty string");
        } else {
            logln("DateTimeRule dtr1 : " + str);
        }
        str = dtr2.toString();
        if (str == null || str.length() == 0) {
            errln("FAIL: DateTimeRule#toString for dtr2 returns null or empty string");
        } else {
            logln("DateTimeRule dtr1 : " + str);
        }
        str = dtr3.toString();
        if (str == null || str.length() == 0) {
            errln("FAIL: DateTimeRule#toString for dtr3 returns null or empty string");
        } else {
            logln("DateTimeRule dtr1 : " + str);
        }
        str = dtr4.toString();
        if (str == null || str.length() == 0) {
            errln("FAIL: DateTimeRule#toString for dtr4 returns null or empty string");
        } else {
            logln("DateTimeRule dtr1 : " + str);
        }
View Full Code Here

                -8*HOUR,        // Raw offset
                0*HOUR);        // DST saving amount

        RuleBasedTimeZone rbPT = new RuleBasedTimeZone("Rule based Pacific Time", ir);

        DateTimeRule dtr;
        AnnualTimeZoneRule atzr;
        final int STARTYEAR = 2000;

        dtr = new DateTimeRule(Calendar.APRIL, 1, Calendar.SUNDAY,
                2*HOUR, DateTimeRule.WALL_TIME); // 1st Sunday in April, at 2AM wall time
        atzr = new AnnualTimeZoneRule("Pacific Daylight Time",
                -8*HOUR /* rawOffset */, 1*HOUR /* dstSavings */, dtr,
                STARTYEAR, AnnualTimeZoneRule.MAX_YEAR);
        rbPT.addTransitionRule(atzr);

        dtr = new DateTimeRule(Calendar.OCTOBER, -1, Calendar.SUNDAY,
                2*HOUR, DateTimeRule.WALL_TIME); // last Sunday in October, at 2AM wall time
        atzr = new AnnualTimeZoneRule("Pacific Standard Time",
                -8*HOUR /* rawOffset */, 0 /* dstSavings */, dtr,
                STARTYEAR, AnnualTimeZoneRule.MAX_YEAR);
        rbPT.addTransitionRule(atzr);
View Full Code Here

                        && (currentRules[1] instanceof AnnualTimeZoneRule)
                        && (currentRules[2] instanceof AnnualTimeZoneRule)) {
                    // A pair of AnnualTimeZoneRule
                    AnnualTimeZoneRule r1 = (AnnualTimeZoneRule)currentRules[1];
                    AnnualTimeZoneRule r2 = (AnnualTimeZoneRule)currentRules[2];
                    DateTimeRule start, end;
                    int offset1 = r1.getRawOffset() + r1.getDSTSavings();
                    int offset2 = r2.getRawOffset() + r2.getDSTSavings();
                    int sav;
                    if (offset1 > offset2) {
                        start = r1.getRule();
                        end = r2.getRule();
                        sav = offset1 - offset2;
                    } else {
                        start = r2.getRule();
                        end = r1.getRule();
                        sav = offset2 - offset1;
                    }
                    // getSimpleTimeZoneRulesNear always return rules using DOW / WALL_TIME
                    stz.setStartRule(start.getRuleMonth(), start.getRuleWeekInMonth(), start.getRuleDayOfWeek(),
                                            start.getRuleMillisInDay());
                    stz.setEndRule(end.getRuleMonth(), end.getRuleWeekInMonth(), end.getRuleDayOfWeek(),
                                            end.getRuleMillisInDay());
                    // set DST saving amount and start year
                    stz.setDSTSavings(sav);
                } else {
View Full Code Here

            Grego.timeToFields(until[0], dfields);
            endYear = dfields[0];
        }

        // Create the AnnualDateTimeRule
        DateTimeRule adtr = null;
        if (dayOfWeek == 0 && nthDayOfWeek == 0 && dayOfMonth != 0) {
            // Day in month rule, for example, 15th day in the month
            adtr = new DateTimeRule(month, dayOfMonth, timeInDay, DateTimeRule.WALL_TIME);
        } else if (dayOfWeek != 0 && nthDayOfWeek != 0 && dayOfMonth == 0) {
            // Nth day of week rule, for example, last Sunday
            adtr = new DateTimeRule(month, nthDayOfWeek, dayOfWeek, timeInDay, DateTimeRule.WALL_TIME);
        } else if (dayOfWeek != 0 && nthDayOfWeek == 0 && dayOfMonth != 0) {
            // First day of week after day of month rule, for example,
            // first Sunday after 15th day in the month
            adtr = new DateTimeRule(month, dayOfMonth, dayOfWeek, true, timeInDay, DateTimeRule.WALL_TIME);
        } else {
            // RRULE attributes are insufficient
            return null;
        }
View Full Code Here

    /*
     * Write the final time zone rule using RRULE, with no UNTIL attribute
     */
    private static void writeFinalRule(Writer writer, boolean isDst, AnnualTimeZoneRule rule,
            int fromRawOffset, int fromDSTSavings, long startTime) throws IOException{
        DateTimeRule dtrule = toWallTimeRule(rule.getRule(), fromRawOffset, fromDSTSavings);
        int toOffset = rule.getRawOffset() + rule.getDSTSavings();
        switch (dtrule.getDateRuleType()) {
        case DateTimeRule.DOM:
            writeZonePropsByDOM(writer, isDst, rule.getName(), fromRawOffset + fromDSTSavings, toOffset,
                    dtrule.getRuleMonth(), dtrule.getRuleDayOfMonth(), startTime, MAX_TIME);
            break;
        case DateTimeRule.DOW:
            writeZonePropsByDOW(writer, isDst, rule.getName(), fromRawOffset + fromDSTSavings, toOffset,
                    dtrule.getRuleMonth(), dtrule.getRuleWeekInMonth(), dtrule.getRuleDayOfWeek(), startTime, MAX_TIME);
            break;
        case DateTimeRule.DOW_GEQ_DOM:
            writeZonePropsByDOW_GEQ_DOM(writer, isDst, rule.getName(), fromRawOffset + fromDSTSavings, toOffset,
                    dtrule.getRuleMonth(), dtrule.getRuleDayOfMonth(), dtrule.getRuleDayOfWeek(), startTime, MAX_TIME);
            break;
        case DateTimeRule.DOW_LEQ_DOM:
            writeZonePropsByDOW_LEQ_DOM(writer, isDst, rule.getName(), fromRawOffset + fromDSTSavings, toOffset,
                    dtrule.getRuleMonth(), dtrule.getRuleDayOfMonth(), dtrule.getRuleDayOfWeek(), startTime, MAX_TIME);
            break;
        }
    }
View Full Code Here

                    dow = Calendar.SUNDAY;
                }
            }
        }
        // Create a new rule
        DateTimeRule modifiedRule;
        if (dtype == DateTimeRule.DOM) {
            modifiedRule = new DateTimeRule(month, dom, wallt, DateTimeRule.WALL_TIME);
        } else {
            modifiedRule = new DateTimeRule(month, dom, dow,
                    (dtype == DateTimeRule.DOW_GEQ_DOM), wallt, DateTimeRule.WALL_TIME);
        }
        return modifiedRule;
    }
View Full Code Here

    private static class DateTimeRuleHandler implements Handler {
        public Object[] getTestObjects() {
            DateTimeRule[] rules = new DateTimeRule[4];

            // DOM + UTC
            rules[0] = new DateTimeRule(Calendar.OCTOBER, 10, 13*HOUR, DateTimeRule.UTC_TIME);

            // DOW + WALL
            rules[1] = new DateTimeRule(Calendar.MARCH, 2, Calendar.SUNDAY, 2*HOUR, DateTimeRule.WALL_TIME);

            // DOW_GEQ_DOM + STD
            rules[2] = new DateTimeRule(Calendar.MAY, 1, Calendar.MONDAY, true, 0*HOUR, DateTimeRule.STANDARD_TIME);

            // DOW_LEQ_DOM + WALL
            rules[3] = new DateTimeRule(Calendar.AUGUST, 31, Calendar.SATURDAY, false, 1*HOUR, DateTimeRule.WALL_TIME);

            return rules;
        }
View Full Code Here

TOP

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

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.