/** * @bug 4154537 * SimpleTimeZone::hasSameRules() doesn't work for zones with no DST * and different DST parameters. */ void TimeZoneRegressionTest:: Test4154537() { UErrorCode status = U_ZERO_ERROR; // tz1 and tz2 have no DST and different rule parameters SimpleTimeZone *tz1 = new SimpleTimeZone(0, "1", 0, 0, 0, 0, 2, 0, 0, 0, status); SimpleTimeZone *tz2 = new SimpleTimeZone(0, "2", 1, 0, 0, 0, 3, 0, 0, 0, status); // tza and tzA have the same rule params SimpleTimeZone *tza = new SimpleTimeZone(0, "a", 0, 1, 0, 0, 3, 2, 0, 0, status); SimpleTimeZone *tzA = new SimpleTimeZone(0, "A", 0, 1, 0, 0, 3, 2, 0, 0, status); // tzb differs from tza SimpleTimeZone *tzb = new SimpleTimeZone(0, "b", 0, 1, 0, 0, 3, 1, 0, 0, status); if(U_FAILURE(status)) errln("Couldn't create TimeZones"); if (tz1->useDaylightTime() || tz2->useDaylightTime() || !tza->useDaylightTime() || !tzA->useDaylightTime() || !tzb->useDaylightTime()) { errln("Test is broken -- rewrite it"); } if (!tza->hasSameRules(*tzA) || tza->hasSameRules(*tzb)) { errln("Fail: hasSameRules() broken for zones with rules"); } if (!tz1->hasSameRules(*tz2)) { errln("Fail: hasSameRules() returns false for zones without rules"); //errln("zone 1 = " + tz1); //errln("zone 2 = " + tz2); } delete tz1; delete tz2; delete tza; delete tzA; delete tzb; }
// {sfb} will this work using a Calendar? void TimeZoneRegressionTest:: Test4073215() { UErrorCode status = U_ZERO_ERROR; UnicodeString str, str2; SimpleTimeZone *z = new SimpleTimeZone(0, "GMT"); if (z->useDaylightTime()) errln("Fail: Fix test to start with non-DST zone"); z->setStartRule(UCAL_FEBRUARY, 1, UCAL_SUNDAY, 0, status); failure(status, "z->setStartRule()"); z->setEndRule(UCAL_MARCH, -1, UCAL_SUNDAY, 0, status); failure(status, "z->setStartRule()"); if (!z->useDaylightTime()) errln("Fail: DST not active"); GregorianCalendar cal(1997, UCAL_JANUARY, 31, status); if(U_FAILURE(status)) { dataerrln("Error creating calendar %s", u_errorName(status)); return; } failure(status, "new GregorianCalendar"); cal.adoptTimeZone(z); SimpleDateFormat sdf((UnicodeString)"E d MMM yyyy G HH:mm", status); if(U_FAILURE(status)) { dataerrln("Error creating date format %s", u_errorName(status)); return; } sdf.setCalendar(cal); failure(status, "new SimpleDateFormat"); UDate jan31, mar1, mar31; UBool indt = z->inDaylightTime(jan31=cal.getTime(status), status); failure(status, "inDaylightTime or getTime call on Jan 31"); if (indt) { errln("Fail: Jan 31 inDaylightTime=TRUE, exp FALSE"); } cal.set(1997, UCAL_MARCH, 1); indt = z->inDaylightTime(mar1=cal.getTime(status), status); failure(status, "inDaylightTime or getTime call on Mar 1"); if (!indt) { UnicodeString str; sdf.format(cal.getTime(status), str); failure(status, "getTime"); errln((UnicodeString)"Fail: " + str + " inDaylightTime=FALSE, exp TRUE"); } cal.set(1997, UCAL_MARCH, 31); indt = z->inDaylightTime(mar31=cal.getTime(status), status); failure(status, "inDaylightTime or getTime call on Mar 31"); if (indt) { errln("Fail: Mar 31 inDaylightTime=TRUE, exp FALSE"); } /* cal.set(1997, Calendar::DECEMBER, 31); UDate dec31 = cal.getTime(status); failure(status, "getTime"); UDate trans = findTransitionStepwise(*z, jan31, dec31); logln((UnicodeString)"Stepwise from " + sdf.format(jan31, str.remove()) + "; transition at " + (trans?sdf.format(trans, str2.remove()):(UnicodeString)"NONE")); trans = findTransitionStepwise(*z, mar1, dec31); logln((UnicodeString)"Stepwise from " + sdf.format(mar1, str.remove()) + "; transition at " + (trans?sdf.format(trans, str2.remove()):(UnicodeString)"NONE")); trans = findTransitionStepwise(*z, mar31, dec31); logln((UnicodeString)"Stepwise from " + sdf.format(mar31, str.remove()) + "; transition at " + (trans?sdf.format(trans, str2.remove()):(UnicodeString)"NONE")); */ }