0001: //##header
0002: /**
0003: *******************************************************************************
0004: * Copyright (C) 2000-2006, International Business Machines Corporation and *
0005: * others. All Rights Reserved. *
0006: *******************************************************************************
0007: */
0008:
0009: /**
0010: * @test 1.18 99/09/21
0011: * @bug 4052967 4073209 4073215 4084933 4096952 4109314 4126678 4151406 4151429
0012: * @bug 4154525 4154537 4154542 4154650 4159922 4162593 4173604 4176686 4184229 4208960
0013: */package com.ibm.icu.dev.test.timezone;
0014:
0015: import com.ibm.icu.util.*;
0016: import java.io.*;
0017: import com.ibm.icu.text.*;
0018: import com.ibm.icu.dev.test.*;
0019: import java.util.Date;
0020: import java.util.Locale;
0021:
0022: public class TimeZoneRegression extends TestFmwk {
0023:
0024: public static void main(String[] args) throws Exception {
0025: new TimeZoneRegression().run(args);
0026: }
0027:
0028: public void Test4052967() {
0029: logln("*** CHECK TIMEZONE AGAINST HOST OS SETTING ***");
0030: String id = TimeZone.getDefault().getID();
0031: try {
0032: // user.timezone is a protected system property
0033: logln("user.timezone: "
0034: + System.getProperty("user.timezone", "<not set>"));
0035: logln("TimeZone.getDefault().getID(): " + id);
0036: logln(new Date().toString());
0037: logln("*** THE RESULTS OF THIS TEST MUST BE VERIFIED MANUALLY ***");
0038: } catch (SecurityException e) {
0039: warnln("security exception: " + e.toString());
0040: }
0041: }
0042:
0043: public void Test4073209() {
0044: TimeZone z1 = TimeZone.getTimeZone("PST");
0045: TimeZone z2 = TimeZone.getTimeZone("PST");
0046: if (z1 == z2)
0047: errln("Fail: TimeZone should return clones");
0048: }
0049:
0050: public void Test4073215() {
0051: SimpleTimeZone z = new SimpleTimeZone(0, "GMT");
0052: if (z.useDaylightTime())
0053: errln("Fail: Fix test to start with non-DST zone");
0054: z.setStartRule(Calendar.FEBRUARY, 1, Calendar.SUNDAY, 0);
0055: z.setEndRule(Calendar.MARCH, -1, Calendar.SUNDAY, 0);
0056: if (!z.useDaylightTime())
0057: errln("Fail: DST not active");
0058: Calendar tempcal = Calendar.getInstance();
0059: tempcal.clear();
0060: tempcal.setTimeZone(z);
0061: tempcal.set(1997, Calendar.JANUARY, 31);
0062: Date d1 = tempcal.getTime();
0063: if (z.inDaylightTime(d1)) {
0064: errln("Fail: DST not working as expected");
0065: }
0066:
0067: tempcal.set(1997, Calendar.MARCH, 1);
0068: Date d2 = tempcal.getTime();
0069: if (!z.inDaylightTime(d2)) {
0070: errln("Fail: DST not working as expected");
0071: }
0072: tempcal.clear();
0073: tempcal.set(1997, Calendar.MARCH, 31);
0074: Date d3 = tempcal.getTime();
0075: if (z.inDaylightTime(d3)) {
0076: errln("Fail: DST not working as expected");
0077: }
0078: }
0079:
0080: /**
0081: * The expected behavior of TimeZone around the boundaries is:
0082: * (Assume transition time of 2:00 AM)
0083: * day of onset 1:59 AM STD = display name 1:59 AM ST
0084: * 2:00 AM STD = display name 3:00 AM DT
0085: * day of end 0:59 AM STD = display name 1:59 AM DT
0086: * 1:00 AM STD = display name 1:00 AM ST
0087: */
0088: public void Test4084933() {
0089: TimeZone tz = TimeZone.getTimeZone("PST");
0090:
0091: long offset1 = tz.getOffset(1, 1997, Calendar.OCTOBER, 26,
0092: Calendar.SUNDAY, (2 * 60 * 60 * 1000));
0093: long offset2 = tz.getOffset(1, 1997, Calendar.OCTOBER, 26,
0094: Calendar.SUNDAY, (2 * 60 * 60 * 1000) - 1);
0095:
0096: long offset3 = tz.getOffset(1, 1997, Calendar.OCTOBER, 26,
0097: Calendar.SUNDAY, (1 * 60 * 60 * 1000));
0098: long offset4 = tz.getOffset(1, 1997, Calendar.OCTOBER, 26,
0099: Calendar.SUNDAY, (1 * 60 * 60 * 1000) - 1);
0100:
0101: /*
0102: * The following was added just for consistency. It shows that going *to* Daylight
0103: * Savings Time (PDT) does work at 2am.
0104: */
0105:
0106: long offset5 = tz.getOffset(1, 1997, Calendar.APRIL, 6,
0107: Calendar.SUNDAY, (2 * 60 * 60 * 1000));
0108: long offset6 = tz.getOffset(1, 1997, Calendar.APRIL, 6,
0109: Calendar.SUNDAY, (2 * 60 * 60 * 1000) - 1);
0110:
0111: long offset7 = tz.getOffset(1, 1997, Calendar.APRIL, 6,
0112: Calendar.SUNDAY, (1 * 60 * 60 * 1000));
0113: long offset8 = tz.getOffset(1, 1997, Calendar.APRIL, 6,
0114: Calendar.SUNDAY, (1 * 60 * 60 * 1000) - 1);
0115:
0116: long SToffset = -8 * 60 * 60 * 1000L;
0117: long DToffset = -7 * 60 * 60 * 1000L;
0118: if (offset1 != SToffset || offset2 != SToffset
0119: || offset3 != SToffset || offset4 != DToffset
0120: || offset5 != DToffset || offset6 != SToffset
0121: || offset7 != SToffset || offset8 != SToffset)
0122: warnln("Fail: TimeZone misbehaving");
0123: }
0124:
0125: public void Test4096952() {
0126: String[] ZONES = { "GMT", "MET", "IST" };
0127: boolean pass = true;
0128: try {
0129: for (int i = 0; i < ZONES.length; ++i) {
0130: TimeZone zone = TimeZone.getTimeZone(ZONES[i]);
0131: if (!zone.getID().equals(ZONES[i]))
0132: warnln("Fail: Test broken; zones not instantiating");
0133:
0134: ByteArrayOutputStream baos;
0135: ObjectOutputStream ostream = new ObjectOutputStream(
0136: baos = new ByteArrayOutputStream());
0137: ostream.writeObject(zone);
0138: ostream.close();
0139: baos.close();
0140: ObjectInputStream istream = new ObjectInputStream(
0141: new ByteArrayInputStream(baos.toByteArray()));
0142: TimeZone frankenZone = (TimeZone) istream.readObject();
0143: //logln("Zone: " + zone);
0144: //logln("FrankenZone: " + frankenZone);
0145: if (!zone.equals(frankenZone)) {
0146: logln("TimeZone "
0147: + zone.getID()
0148: + " not equal to serialized/deserialized one");
0149: pass = false;
0150: }
0151: }
0152: if (!pass)
0153: errln("Fail: TimeZone serialization/equality bug");
0154: } catch (IOException e) {
0155: errln("Fail: " + e);
0156: e.printStackTrace();
0157: } catch (ClassNotFoundException e) {
0158: errln("Fail: " + e);
0159: e.printStackTrace();
0160: }
0161: }
0162:
0163: public void Test4109314() {
0164: GregorianCalendar testCal = (GregorianCalendar) Calendar
0165: .getInstance();
0166: TimeZone PST = TimeZone.getTimeZone("PST");
0167: java.util.Calendar tempcal = java.util.Calendar.getInstance();
0168: tempcal.clear();
0169: tempcal.set(1998, Calendar.APRIL, 4, 22, 0);
0170: Date d1 = tempcal.getTime();
0171: tempcal.set(1998, Calendar.APRIL, 5, 6, 0);
0172: Date d2 = tempcal.getTime();
0173: tempcal.set(1998, Calendar.OCTOBER, 24, 22, 0);
0174: Date d3 = tempcal.getTime();
0175: tempcal.set(1998, Calendar.OCTOBER, 25, 6, 0);
0176: Date d4 = tempcal.getTime();
0177: Object[] testData = { PST, d1, d2, PST, d3, d4, };
0178: boolean pass = true;
0179: for (int i = 0; i < testData.length; i += 3) {
0180: testCal.setTimeZone((TimeZone) testData[i]);
0181: long t = ((Date) testData[i + 1]).getTime();
0182: Date end = (Date) testData[i + 2];
0183: while (t < end.getTime()) {
0184: testCal.setTime(new Date(t));
0185: if (!checkCalendar314(testCal, (TimeZone) testData[i]))
0186: pass = false;
0187: t += 60 * 60 * 1000L;
0188: }
0189: }
0190: if (!pass)
0191: errln("Fail: TZ API inconsistent");
0192: }
0193:
0194: boolean checkCalendar314(GregorianCalendar testCal, TimeZone testTZ) {
0195: // GregorianCalendar testCal = (GregorianCalendar)aCal.clone();
0196:
0197: final int ONE_DAY = 24 * 60 * 60 * 1000;
0198:
0199: int tzOffset, tzRawOffset;
0200: Float tzOffsetFloat, tzRawOffsetFloat;
0201: // Here is where the user made an error. They were passing in the value of
0202: // the MILLSECOND field; you need to pass in the millis in the day in STANDARD
0203: // time.
0204: int millis = testCal.get(Calendar.MILLISECOND)
0205: + 1000
0206: * (testCal.get(Calendar.SECOND) + 60 * (testCal
0207: .get(Calendar.MINUTE) + 60 * (testCal
0208: .get(Calendar.HOUR_OF_DAY))))
0209: - testCal.get(Calendar.DST_OFFSET);
0210:
0211: /* Fix up millis to be in range. ASSUME THAT WE ARE NOT AT THE
0212: * BEGINNING OR END OF A MONTH. We must add this code because
0213: * getOffset() has been changed to be more strict about the parameters
0214: * it receives -- it turns out that this test was passing in illegal
0215: * values. */
0216: int date = testCal.get(Calendar.DATE);
0217: int dow = testCal.get(Calendar.DAY_OF_WEEK);
0218: while (millis < 0) {
0219: millis += ONE_DAY;
0220: --date;
0221: dow = Calendar.SUNDAY + ((dow - Calendar.SUNDAY + 6) % 7);
0222: }
0223: while (millis >= ONE_DAY) {
0224: millis -= ONE_DAY;
0225: ++date;
0226: dow = Calendar.SUNDAY + ((dow - Calendar.SUNDAY + 1) % 7);
0227: }
0228:
0229: tzOffset = testTZ.getOffset(testCal.get(Calendar.ERA), testCal
0230: .get(Calendar.YEAR), testCal.get(Calendar.MONTH), date,
0231: dow, millis);
0232: tzRawOffset = testTZ.getRawOffset();
0233: tzOffsetFloat = new Float((float) tzOffset / (float) 3600000);
0234: tzRawOffsetFloat = new Float((float) tzRawOffset
0235: / (float) 3600000);
0236:
0237: Date testDate = testCal.getTime();
0238:
0239: boolean inDaylightTime = testTZ.inDaylightTime(testDate);
0240: SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm");
0241: sdf.setCalendar(testCal);
0242: String inDaylightTimeString;
0243:
0244: boolean passed;
0245:
0246: if (inDaylightTime) {
0247: inDaylightTimeString = " DST ";
0248: passed = (tzOffset == (tzRawOffset + 3600000));
0249: } else {
0250: inDaylightTimeString = " ";
0251: passed = (tzOffset == tzRawOffset);
0252: }
0253:
0254: String output = testTZ.getID() + " " + sdf.format(testDate)
0255: + " Offset(" + tzOffsetFloat + ")" + " RawOffset("
0256: + tzRawOffsetFloat + ")" + " " + millis
0257: / (float) 3600000 + " " + inDaylightTimeString;
0258:
0259: if (passed)
0260: output += " ";
0261: else
0262: output += "ERROR";
0263:
0264: if (passed)
0265: logln(output);
0266: else
0267: errln(output);
0268: return passed;
0269: }
0270:
0271: /**
0272: * CANNOT REPRODUDE
0273: *
0274: * Yet another _alleged_ bug in TimeZone.getOffset(), a method that never
0275: * should have been made public. It's simply too hard to use correctly.
0276: *
0277: * The original test code failed to do the following:
0278: * (1) Call Calendar.setTime() before getting the fields!
0279: * (2) Use the right millis (as usual) for getOffset(); they were passing
0280: * in the MILLIS field, instead of the STANDARD MILLIS IN DAY.
0281: * When you fix these two problems, the test passes, as expected.
0282: */
0283: public void Test4126678() {
0284: // Note: this test depends on the PST time zone.
0285: TimeZone initialZone = TimeZone.getDefault();
0286: Calendar cal = Calendar.getInstance();
0287: TimeZone tz = TimeZone.getTimeZone("PST");
0288: TimeZone.setDefault(tz);
0289: cal.setTimeZone(tz);
0290:
0291: java.util.Calendar tempcal = java.util.Calendar.getInstance();
0292: tempcal.clear();
0293: tempcal.set(1998, Calendar.APRIL, 5, 10, 0);
0294: Date dt = tempcal.getTime();
0295: // the dt value is local time in PST.
0296: if (!tz.inDaylightTime(dt))
0297: errln("We're not in Daylight Savings Time and we should be.\n");
0298:
0299: cal.setTime(dt);
0300: int era = cal.get(Calendar.ERA);
0301: int year = cal.get(Calendar.YEAR);
0302: int month = cal.get(Calendar.MONTH);
0303: int day = cal.get(Calendar.DATE);
0304: int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
0305: int millis = cal.get(Calendar.MILLISECOND)
0306: + (cal.get(Calendar.SECOND) + (cal.get(Calendar.MINUTE) + (cal
0307: .get(Calendar.HOUR) * 60) * 60) * 1000)
0308: - cal.get(Calendar.DST_OFFSET);
0309:
0310: long offset = tz.getOffset(era, year, month, day, dayOfWeek,
0311: millis);
0312: long raw_offset = tz.getRawOffset();
0313: if (offset == raw_offset)
0314: errln("Offsets should not match when in DST");
0315:
0316: // restore the initial time zone so that this test case
0317: // doesn't affect the others.
0318: TimeZone.setDefault(initialZone);
0319: }
0320:
0321: /**
0322: * TimeZone.getAvailableIDs(int) throws exception for certain values,
0323: * due to a faulty constant in TimeZone.java.
0324: */
0325: public void Test4151406() {
0326: int max = 0;
0327: for (int h = -28; h <= 30; ++h) {
0328: // h is in half-hours from GMT; rawoffset is in millis
0329: int rawoffset = h * 1800000;
0330: int hh = (h < 0) ? -h : h;
0331: String hname = ((h < 0) ? "GMT-" : "GMT+")
0332: + ((hh / 2 < 10) ? "0" : "") + (hh / 2) + ':'
0333: + ((hh % 2 == 0) ? "00" : "30");
0334: try {
0335: String[] ids = TimeZone.getAvailableIDs(rawoffset);
0336: if (ids.length > max)
0337: max = ids.length;
0338: logln(hname + ' ' + ids.length
0339: + ((ids.length > 0) ? (" e.g. " + ids[0]) : ""));
0340: } catch (Exception e) {
0341: errln(hname + ' ' + "Fail: " + e);
0342: }
0343: }
0344: logln("Maximum zones per offset = " + max);
0345: }
0346:
0347: public void Test4151429() {
0348: try {
0349: TimeZone tz = TimeZone.getTimeZone("GMT");
0350: /*String name =*/tz.getDisplayName(true,
0351: Integer.MAX_VALUE, Locale.getDefault());
0352: errln("IllegalArgumentException not thrown by TimeZone.getDisplayName()");
0353: } catch (IllegalArgumentException e) {
0354: System.out.print("");
0355: }
0356: }
0357:
0358: /**
0359: * SimpleTimeZone accepts illegal DST savings values. These values
0360: * must be non-zero. There is no upper limit at this time.
0361: */
0362: public void Test4154525() {
0363: final int GOOD = 1, BAD = 0;
0364: int[] DATA = { 1, GOOD, 0, BAD, -1, BAD, 60 * 60 * 1000, GOOD,
0365: Integer.MIN_VALUE, BAD,
0366: // Integer.MAX_VALUE, ?, // no upper limit on DST savings at this time
0367: };
0368: for (int i = 0; i < DATA.length; i += 2) {
0369: int savings = DATA[i];
0370: boolean valid = DATA[i + 1] == GOOD;
0371: String method = null;
0372: for (int j = 0; j < 2; ++j) {
0373: try {
0374: switch (j) {
0375: case 0:
0376: method = "constructor";
0377: SimpleTimeZone z = new SimpleTimeZone(0, "id",
0378: Calendar.JANUARY, 1, 0, 0,
0379: Calendar.MARCH, 1, 0, 0, savings); // <- what we're interested in
0380: break;
0381: case 1:
0382: method = "setDSTSavings()";
0383: z = new SimpleTimeZone(0, "GMT");
0384: z.setDSTSavings(savings);
0385: break;
0386: }
0387: if (valid) {
0388: logln("Pass: DST savings of " + savings
0389: + " accepted by " + method);
0390: } else {
0391: errln("Fail: DST savings of " + savings
0392: + " accepted by " + method);
0393: }
0394: } catch (IllegalArgumentException e) {
0395: if (valid) {
0396: errln("Fail: DST savings of " + savings
0397: + " to " + method + " gave " + e);
0398: } else {
0399: logln("Pass: DST savings of " + savings
0400: + " to " + method + " gave " + e);
0401: }
0402: }
0403: }
0404: }
0405: }
0406:
0407: /**
0408: * SimpleTimeZone.hasSameRules() doesn't work for zones with no DST
0409: * and different DST parameters.
0410: */
0411: public void Test4154537() {
0412: // tz1 and tz2 have no DST and different rule parameters
0413: SimpleTimeZone tz1 = new SimpleTimeZone(0, "1", 0, 0, 0, 0, 2,
0414: 0, 0, 0);
0415: SimpleTimeZone tz2 = new SimpleTimeZone(0, "2", 1, 0, 0, 0, 3,
0416: 0, 0, 0);
0417: // tza and tzA have the same rule params
0418: SimpleTimeZone tza = new SimpleTimeZone(0, "a", 0, 1, 0, 0, 3,
0419: 2, 0, 0);
0420: SimpleTimeZone tzA = new SimpleTimeZone(0, "A", 0, 1, 0, 0, 3,
0421: 2, 0, 0);
0422: // tzb differs from tza
0423: SimpleTimeZone tzb = new SimpleTimeZone(0, "b", 0, 1, 0, 0, 3,
0424: 1, 0, 0);
0425: if (tz1.useDaylightTime() || tz2.useDaylightTime()
0426: || !tza.useDaylightTime() || !tzA.useDaylightTime()
0427: || !tzb.useDaylightTime()) {
0428: errln("Test is broken -- rewrite it");
0429: }
0430: if (!tza.hasSameRules(tzA) || tza.hasSameRules(tzb)) {
0431: errln("Fail: hasSameRules() broken for zones with rules");
0432: }
0433: if (!tz1.hasSameRules(tz2)) {
0434: errln("Fail: hasSameRules() returns false for zones without rules");
0435: errln("zone 1 = " + tz1);
0436: errln("zone 2 = " + tz2);
0437: }
0438: }
0439:
0440: /**
0441: * SimpleTimeZone constructors, setStartRule(), and setEndRule() don't
0442: * check for out-of-range arguments.
0443: */
0444: public void Test4154542() {
0445: final int GOOD = 1;
0446: final int BAD = 0;
0447:
0448: final int GOOD_MONTH = Calendar.JANUARY;
0449: final int GOOD_DAY = 1;
0450: final int GOOD_DAY_OF_WEEK = Calendar.SUNDAY;
0451: final int GOOD_TIME = 0;
0452:
0453: int[] DATA = { GOOD, Integer.MIN_VALUE, 0, Integer.MAX_VALUE,
0454: Integer.MIN_VALUE, GOOD, Calendar.JANUARY, -5,
0455: Calendar.SUNDAY, 0, GOOD, Calendar.DECEMBER, 5,
0456: Calendar.SATURDAY, 24 * 60 * 60 * 1000 - 1, BAD,
0457: Calendar.DECEMBER, 5, Calendar.SATURDAY,
0458: 24 * 60 * 60 * 1000 + 1, BAD, Calendar.DECEMBER, 5,
0459: Calendar.SATURDAY, -1, BAD, Calendar.JANUARY, -6,
0460: Calendar.SUNDAY, 0, BAD, Calendar.DECEMBER, 6,
0461: Calendar.SATURDAY, 24 * 60 * 60 * 1000, GOOD,
0462: Calendar.DECEMBER, 1, 0, 0, GOOD, Calendar.DECEMBER,
0463: 31, 0, 0, BAD, Calendar.APRIL, 31, 0, 0, BAD,
0464: Calendar.DECEMBER, 32, 0, 0, BAD, Calendar.JANUARY - 1,
0465: 1, Calendar.SUNDAY, 0, BAD, Calendar.DECEMBER + 1, 1,
0466: Calendar.SUNDAY, 0, GOOD, Calendar.DECEMBER, 31,
0467: -Calendar.SUNDAY, 0, GOOD, Calendar.DECEMBER, 31,
0468: -Calendar.SATURDAY, 0, BAD, Calendar.DECEMBER, 32,
0469: -Calendar.SATURDAY, 0, BAD, Calendar.DECEMBER, -32,
0470: -Calendar.SATURDAY, 0, BAD, Calendar.DECEMBER, 31,
0471: -Calendar.SATURDAY - 1, 0, };
0472: SimpleTimeZone zone = new SimpleTimeZone(0, "Z");
0473: for (int i = 0; i < DATA.length; i += 5) {
0474: boolean shouldBeGood = (DATA[i] == GOOD);
0475: int month = DATA[i + 1];
0476: int day = DATA[i + 2];
0477: int dayOfWeek = DATA[i + 3];
0478: int time = DATA[i + 4];
0479:
0480: Exception ex = null;
0481: try {
0482: zone.setStartRule(month, day, dayOfWeek, time);
0483: } catch (IllegalArgumentException e) {
0484: ex = e;
0485: }
0486: if ((ex == null) != shouldBeGood) {
0487: errln("setStartRule(month="
0488: + month
0489: + ", day="
0490: + day
0491: + ", dayOfWeek="
0492: + dayOfWeek
0493: + ", time="
0494: + time
0495: + (shouldBeGood ? (") should work but throws " + ex)
0496: : ") should fail but doesn't"));
0497: }
0498:
0499: ex = null;
0500: try {
0501: zone.setEndRule(month, day, dayOfWeek, time);
0502: } catch (IllegalArgumentException e) {
0503: ex = e;
0504: }
0505: if ((ex == null) != shouldBeGood) {
0506: errln("setEndRule(month="
0507: + month
0508: + ", day="
0509: + day
0510: + ", dayOfWeek="
0511: + dayOfWeek
0512: + ", time="
0513: + time
0514: + (shouldBeGood ? (") should work but throws " + ex)
0515: : ") should fail but doesn't"));
0516: }
0517:
0518: ex = null;
0519: try {
0520: /*SimpleTimeZone temp =*/new SimpleTimeZone(0, "Z",
0521: month, day, dayOfWeek, time, GOOD_MONTH,
0522: GOOD_DAY, GOOD_DAY_OF_WEEK, GOOD_TIME);
0523: } catch (IllegalArgumentException e) {
0524: ex = e;
0525: }
0526: if ((ex == null) != shouldBeGood) {
0527: errln("SimpleTimeZone(month="
0528: + month
0529: + ", day="
0530: + day
0531: + ", dayOfWeek="
0532: + dayOfWeek
0533: + ", time="
0534: + time
0535: + (shouldBeGood ? (", <end>) should work but throws " + ex)
0536: : ", <end>) should fail but doesn't"));
0537: }
0538:
0539: ex = null;
0540: try {
0541: /*SimpleTimeZone temp = */new SimpleTimeZone(0, "Z",
0542: GOOD_MONTH, GOOD_DAY, GOOD_DAY_OF_WEEK,
0543: GOOD_TIME, month, day, dayOfWeek, time);
0544: // temp = null;
0545: } catch (IllegalArgumentException e) {
0546: ex = e;
0547: }
0548: if ((ex == null) != shouldBeGood) {
0549: errln("SimpleTimeZone(<start>, month="
0550: + month
0551: + ", day="
0552: + day
0553: + ", dayOfWeek="
0554: + dayOfWeek
0555: + ", time="
0556: + time
0557: + (shouldBeGood ? (") should work but throws " + ex)
0558: : ") should fail but doesn't"));
0559: }
0560: }
0561: }
0562:
0563: /**
0564: * SimpleTimeZone.getOffset accepts illegal arguments.
0565: */
0566: public void Test4154650() {
0567: final int GOOD = 1, BAD = 0;
0568: final int GOOD_ERA = GregorianCalendar.AD, GOOD_YEAR = 1998, GOOD_MONTH = Calendar.AUGUST;
0569: final int GOOD_DAY = 2, GOOD_DOW = Calendar.SUNDAY, GOOD_TIME = 16 * 3600000;
0570: int[] DATA = { GOOD, GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY,
0571: GOOD_DOW, GOOD_TIME,
0572:
0573: GOOD, GregorianCalendar.BC, GOOD_YEAR, GOOD_MONTH,
0574: GOOD_DAY, GOOD_DOW, GOOD_TIME, GOOD,
0575: GregorianCalendar.AD, GOOD_YEAR, GOOD_MONTH, GOOD_DAY,
0576: GOOD_DOW, GOOD_TIME, BAD, GregorianCalendar.BC - 1,
0577: GOOD_YEAR, GOOD_MONTH, GOOD_DAY, GOOD_DOW, GOOD_TIME,
0578: BAD, GregorianCalendar.AD + 1, GOOD_YEAR, GOOD_MONTH,
0579: GOOD_DAY, GOOD_DOW, GOOD_TIME,
0580:
0581: GOOD, GOOD_ERA, GOOD_YEAR, Calendar.JANUARY, GOOD_DAY,
0582: GOOD_DOW, GOOD_TIME, GOOD, GOOD_ERA, GOOD_YEAR,
0583: Calendar.DECEMBER, GOOD_DAY, GOOD_DOW, GOOD_TIME, BAD,
0584: GOOD_ERA, GOOD_YEAR, Calendar.JANUARY - 1, GOOD_DAY,
0585: GOOD_DOW, GOOD_TIME, BAD, GOOD_ERA, GOOD_YEAR,
0586: Calendar.DECEMBER + 1, GOOD_DAY, GOOD_DOW, GOOD_TIME,
0587:
0588: GOOD, GOOD_ERA, GOOD_YEAR, Calendar.JANUARY, 1,
0589: GOOD_DOW, GOOD_TIME, GOOD, GOOD_ERA, GOOD_YEAR,
0590: Calendar.JANUARY, 31, GOOD_DOW, GOOD_TIME, BAD,
0591: GOOD_ERA, GOOD_YEAR, Calendar.JANUARY, 0, GOOD_DOW,
0592: GOOD_TIME, BAD, GOOD_ERA, GOOD_YEAR, Calendar.JANUARY,
0593: 32, GOOD_DOW, GOOD_TIME,
0594:
0595: GOOD, GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY,
0596: Calendar.SUNDAY, GOOD_TIME, GOOD, GOOD_ERA, GOOD_YEAR,
0597: GOOD_MONTH, GOOD_DAY, Calendar.SATURDAY, GOOD_TIME,
0598: BAD, GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY,
0599: Calendar.SUNDAY - 1, GOOD_TIME, BAD, GOOD_ERA,
0600: GOOD_YEAR, GOOD_MONTH, GOOD_DAY, Calendar.SATURDAY + 1,
0601: GOOD_TIME,
0602:
0603: GOOD, GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY,
0604: GOOD_DOW, 0, GOOD, GOOD_ERA, GOOD_YEAR, GOOD_MONTH,
0605: GOOD_DAY, GOOD_DOW, 24 * 3600000 - 1, BAD, GOOD_ERA,
0606: GOOD_YEAR, GOOD_MONTH, GOOD_DAY, GOOD_DOW, -1, BAD,
0607: GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, GOOD_DOW,
0608: 24 * 3600000, };
0609:
0610: TimeZone tz = TimeZone.getDefault();
0611: for (int i = 0; i < DATA.length; i += 7) {
0612: boolean good = DATA[i] == GOOD;
0613: IllegalArgumentException e = null;
0614: try {
0615: /*int offset =*/tz.getOffset(DATA[i + 1], DATA[i + 2],
0616: DATA[i + 3], DATA[i + 4], DATA[i + 5],
0617: DATA[i + 6]);
0618: //offset = 0;
0619: } catch (IllegalArgumentException ex) {
0620: e = ex;
0621: }
0622: if (good != (e == null)) {
0623: errln("Fail: getOffset("
0624: + DATA[i + 1]
0625: + ", "
0626: + DATA[i + 2]
0627: + ", "
0628: + DATA[i + 3]
0629: + ", "
0630: + DATA[i + 4]
0631: + ", "
0632: + DATA[i + 5]
0633: + ", "
0634: + DATA[i + 6]
0635: + (good ? (") threw " + e)
0636: : ") accepts invalid args"));
0637: }
0638: }
0639: }
0640:
0641: /**
0642: * TimeZone constructors allow null IDs.
0643: */
0644: public void Test4159922() {
0645: TimeZone z = null;
0646:
0647: // TimeZone API. Only hasSameRules() and setDefault() should
0648: // allow null.
0649: try {
0650: z = TimeZone.getTimeZone(null);
0651: errln("FAIL: Null allowed in getTimeZone");
0652: } catch (NullPointerException e) {
0653: System.out.print("");
0654: }
0655: z = TimeZone.getTimeZone("GMT");
0656: try {
0657: // {dlf} requiring cast for disambiguation is ok for compatibility since null
0658: // is not a valid argument to this API
0659: z.getDisplayName(false, TimeZone.SHORT, (ULocale) null);
0660: errln("FAIL: Null allowed in getDisplayName(3)");
0661: } catch (NullPointerException e) {
0662: System.out.print("");
0663: }
0664: try {
0665: // {dlf} see above
0666: z.getDisplayName((ULocale) null);
0667: errln("FAIL: Null allowed in getDisplayName(1)");
0668: } catch (NullPointerException e) {
0669: System.out.print("");
0670: }
0671: try {
0672: if (z.hasSameRules(null)) {
0673: errln("FAIL: hasSameRules returned true");
0674: }
0675: } catch (NullPointerException e) {
0676: errln("FAIL: Null NOT allowed in hasSameRules");
0677: }
0678: try {
0679: z.inDaylightTime(null);
0680: errln("FAIL: Null allowed in inDaylightTime");
0681: } catch (NullPointerException e) {
0682: System.out.print("");
0683: }
0684: try {
0685: z.setID(null);
0686: errln("FAIL: Null allowed in setID");
0687: } catch (NullPointerException e) {
0688: System.out.print("");
0689: }
0690:
0691: TimeZone save = TimeZone.getDefault();
0692: try {
0693: TimeZone.setDefault(null);
0694: } catch (NullPointerException e) {
0695: errln("FAIL: Null NOT allowed in setDefault");
0696: } finally {
0697: TimeZone.setDefault(save);
0698: }
0699:
0700: // SimpleTimeZone API
0701: SimpleTimeZone s = null;
0702: try {
0703: s = new SimpleTimeZone(0, null);
0704: errln("FAIL: Null allowed in SimpleTimeZone(2)");
0705: } catch (NullPointerException e) {
0706: System.out.print("");
0707: }
0708: try {
0709: s = new SimpleTimeZone(0, null, 0, 1, 0, 0, 0, 1, 0, 0);
0710: errln("FAIL: Null allowed in SimpleTimeZone(10)");
0711: } catch (NullPointerException e) {
0712: System.out.print("");
0713: }
0714: try {
0715: s = new SimpleTimeZone(0, null, 0, 1, 0, 0, 0, 1, 0, 0,
0716: 1000);
0717: errln("FAIL: Null allowed in SimpleTimeZone(11)");
0718: } catch (NullPointerException e) {
0719: System.out.print("");
0720: }
0721: if (s != null) {
0722: errln("FAIL: Did not get the expected Exception");
0723: }
0724: }
0725:
0726: /**
0727: * TimeZone broken at midnight. The TimeZone code fails to handle
0728: * transitions at midnight correctly.
0729: */
0730: public void Test4162593() {
0731: SimpleDateFormat fmt = new SimpleDateFormat("z", Locale.US);
0732: final int ONE_HOUR = 60 * 60 * 1000;
0733: final float H = (float) ONE_HOUR;
0734: TimeZone initialZone = TimeZone.getDefault();
0735: SimpleDateFormat sdf = new SimpleDateFormat(
0736: "MMM dd yyyy HH:mm z");
0737:
0738: SimpleTimeZone asuncion = new SimpleTimeZone(-4 * ONE_HOUR,
0739: "America/Asuncion" /*PY%sT*/, Calendar.OCTOBER, 1,
0740: 0 /*DOM*/, 0 * ONE_HOUR, Calendar.MARCH, 1,
0741: 0 /*DOM*/, 0 * ONE_HOUR, 1 * ONE_HOUR);
0742:
0743: /* Zone
0744: * Starting time
0745: * Transition expected between start+1H and start+2H
0746: */
0747: Object[] DATA = {
0748: new SimpleTimeZone(2 * ONE_HOUR,
0749: "Asia/Damascus" /*EE%sT*/, Calendar.APRIL, 1,
0750: 0 /*DOM*/, 0 * ONE_HOUR, Calendar.OCTOBER, 1,
0751: 0 /*DOM*/, 0 * ONE_HOUR, 1 * ONE_HOUR),
0752: new int[] { 1998, Calendar.SEPTEMBER, 30, 22, 0 },
0753: Boolean.TRUE,
0754:
0755: asuncion,
0756: new int[] { 2000, Calendar.FEBRUARY, 28, 22, 0 },
0757: Boolean.FALSE,
0758:
0759: asuncion,
0760: new int[] { 2000, Calendar.FEBRUARY, 29, 22, 0 },
0761: Boolean.TRUE, };
0762:
0763: String[] zone = new String[4];
0764:
0765: for (int j = 0; j < DATA.length; j += 3) {
0766: TimeZone tz = (TimeZone) DATA[j];
0767: TimeZone.setDefault(tz);
0768: fmt.setTimeZone(tz);
0769: sdf.setTimeZone(tz);
0770:
0771: // Must construct the Date object AFTER setting the default zone
0772: int[] p = (int[]) DATA[j + 1];
0773: Calendar cal = Calendar.getInstance();
0774: cal.clear();
0775: cal.set(p[0], p[1], p[2], p[3], p[4]);
0776: long start = cal.getTime().getTime();
0777: boolean transitionExpected = ((Boolean) DATA[j + 2])
0778: .booleanValue();
0779:
0780: logln(tz.getID() + ":");
0781: for (int i = 0; i < 4; ++i) {
0782: Date d = new Date(start + i * ONE_HOUR);
0783: zone[i] = fmt.format(d);
0784: logln("" + i + ": " + sdf.format(d) + " => " + zone[i]
0785: + " (" + d.getTime() / H + ")");
0786: }
0787: cal.set(p[0], p[1], p[2], 0, 0);
0788: for (int i = 0; i < 4; ++i) {
0789: int h = 22 + i;
0790: int dom = p[2] + (h >= 24 ? 1 : 0);
0791: h %= 24;
0792: int ms = h * ONE_HOUR;
0793: cal.clear();
0794: cal.set(p[0], p[1], dom, 0, 0);
0795: int off = tz.getOffset(GregorianCalendar.AD, cal
0796: .get(Calendar.YEAR), cal.get(Calendar.MONTH),
0797: cal.get(Calendar.DATE), cal
0798: .get(Calendar.DAY_OF_WEEK), ms);
0799: cal.add(Calendar.HOUR, h);
0800: int x = cal.get(Calendar.DST_OFFSET);
0801: logln("h=" + h + "; dom=" + dom + "; ZONE_OFFSET="
0802: + cal.get(Calendar.ZONE_OFFSET) / H
0803: + "; DST_OFFSET="
0804: + cal.get(Calendar.DST_OFFSET) / H
0805: + "; getOffset()=" + off / H + " ("
0806: + cal.getTime().getTime() / H + ")");
0807: }
0808: if (zone[0].equals(zone[1])
0809: && (zone[1].equals(zone[2]) != transitionExpected)
0810: && zone[2].equals(zone[3])) {
0811: logln("Ok: transition " + transitionExpected);
0812: } else {
0813: errln("FAIL: expected "
0814: + (transitionExpected ? "transition"
0815: : "no transition"));
0816: }
0817: }
0818:
0819: // restore the initial time zone so that this test case
0820: // doesn't affect the others.
0821: TimeZone.setDefault(initialZone);
0822: }
0823:
0824: /**
0825: * TimeZone broken in last hour of year
0826: */
0827: public void Test4173604() {
0828: TimeZone pst = TimeZone.getTimeZone("PST");
0829: int o22 = pst.getOffset(1, 1998, 11, 31, Calendar.THURSDAY,
0830: 22 * 60 * 60 * 1000);
0831: int o23 = pst.getOffset(1, 1998, 11, 31, Calendar.THURSDAY,
0832: 23 * 60 * 60 * 1000);
0833: int o00 = pst.getOffset(1, 1999, 0, 1, Calendar.FRIDAY, 0);
0834: if (o22 != o23 || o22 != o00) {
0835: errln("Offsets should be the same (for PST), but got: "
0836: + "12/31 22:00 " + o22 + ", 12/31 23:00 " + o23
0837: + ", 01/01 00:00 " + o00);
0838: }
0839:
0840: GregorianCalendar cal = new GregorianCalendar();
0841: cal.setTimeZone(pst);
0842: cal.clear();
0843: cal.set(1998, Calendar.JANUARY, 1);
0844: int lastDST = cal.get(Calendar.DST_OFFSET);
0845: int transitions = 0;
0846: int delta = 5;
0847: while (cal.get(Calendar.YEAR) < 2000) {
0848: cal.add(Calendar.MINUTE, delta);
0849: if (cal.get(Calendar.DST_OFFSET) != lastDST) {
0850: ++transitions;
0851: Calendar t = (Calendar) cal.clone();
0852: t.add(Calendar.MINUTE, -delta);
0853: logln(t.getTime() + " " + t.get(Calendar.DST_OFFSET));
0854: logln(cal.getTime() + " "
0855: + (lastDST = cal.get(Calendar.DST_OFFSET)));
0856: }
0857: }
0858: if (transitions != 4) {
0859: errln("Saw " + transitions
0860: + " transitions; should have seen 4");
0861: }
0862: }
0863:
0864: /**
0865: * getDisplayName doesn't work with unusual savings/offsets.
0866: */
0867: public void Test4176686() {
0868: // Construct a zone that does not observe DST but
0869: // that does have a DST savings (which should be ignored).
0870: int offset = 90 * 60000; // 1:30
0871: SimpleTimeZone z1 = new SimpleTimeZone(offset, "_std_zone_");
0872: z1.setDSTSavings(45 * 60000); // 0:45
0873:
0874: // Construct a zone that observes DST for the first 6 months.
0875: SimpleTimeZone z2 = new SimpleTimeZone(offset, "_dst_zone_");
0876: z2.setDSTSavings(45 * 60000); // 0:45
0877: z2.setStartRule(Calendar.JANUARY, 1, 0);
0878: z2.setEndRule(Calendar.JULY, 1, 0);
0879:
0880: // Also check DateFormat
0881: DateFormat fmt1 = new SimpleDateFormat("z");
0882: fmt1.setTimeZone(z1); // Format uses standard zone
0883: DateFormat fmt2 = new SimpleDateFormat("z");
0884: fmt2.setTimeZone(z2); // Format uses DST zone
0885: java.util.Calendar tempcal = java.util.Calendar.getInstance();
0886: tempcal.clear();
0887: tempcal.set(1970, Calendar.FEBRUARY, 1);
0888: Date dst = tempcal.getTime(); // Time in DST
0889: tempcal.set(1970, Calendar.AUGUST, 1);
0890: Date std = tempcal.getTime(); // Time in standard
0891:
0892: // Description, Result, Expected Result
0893: String[] DATA = { "getDisplayName(false, SHORT)/std zone",
0894: z1.getDisplayName(false, TimeZone.SHORT), "GMT+01:30",
0895: "getDisplayName(false, LONG)/std zone",
0896: z1.getDisplayName(false, TimeZone.LONG), "GMT+01:30",
0897: "getDisplayName(true, SHORT)/std zone",
0898: z1.getDisplayName(true, TimeZone.SHORT), "GMT+01:30",
0899: "getDisplayName(true, LONG)/std zone",
0900: z1.getDisplayName(true, TimeZone.LONG), "GMT+01:30",
0901: "getDisplayName(false, SHORT)/dst zone",
0902: z2.getDisplayName(false, TimeZone.SHORT), "GMT+01:30",
0903: "getDisplayName(false, LONG)/dst zone",
0904: z2.getDisplayName(false, TimeZone.LONG), "GMT+01:30",
0905: "getDisplayName(true, SHORT)/dst zone",
0906: z2.getDisplayName(true, TimeZone.SHORT), "GMT+02:15",
0907: "getDisplayName(true, LONG)/dst zone",
0908: z2.getDisplayName(true, TimeZone.LONG), "GMT+02:15",
0909: "DateFormat.format(std)/std zone", fmt1.format(std),
0910: "GMT+01:30", "DateFormat.format(dst)/std zone",
0911: fmt1.format(dst), "GMT+01:30",
0912: "DateFormat.format(std)/dst zone", fmt2.format(std),
0913: "GMT+01:30", "DateFormat.format(dst)/dst zone",
0914: fmt2.format(dst), "GMT+02:15", };
0915:
0916: for (int i = 0; i < DATA.length; i += 3) {
0917: if (!DATA[i + 1].equals(DATA[i + 2])) {
0918: errln("FAIL: " + DATA[i] + " -> " + DATA[i + 1]
0919: + ", exp " + DATA[i + 2]);
0920: }
0921: }
0922: }
0923:
0924: /**
0925: * SimpleTimeZone allows invalid DOM values.
0926: */
0927: // Current orgnaization of data in zoneinfor.res allows negative
0928: // values from DOM so comment these tests out
0929: public void Test4184229() {
0930: SimpleTimeZone zone = null;
0931: try {
0932: zone = new SimpleTimeZone(0, "A", 0, -1, 0, 0, 0, 0, 0, 0);
0933: errln("Failed. No exception has been thrown for DOM -1 startDay");
0934: } catch (IllegalArgumentException e) {
0935: logln("(a) " + e.getMessage());
0936: }
0937: try {
0938: zone = new SimpleTimeZone(0, "A", 0, 0, 0, 0, 0, -1, 0, 0);
0939: errln("Failed. No exception has been thrown for DOM -1 endDay");
0940: } catch (IllegalArgumentException e) {
0941: logln("(b) " + e.getMessage());
0942: }
0943: try {
0944: zone = new SimpleTimeZone(0, "A", 0, -1, 0, 0, 0, 0, 0, 0,
0945: 1000);
0946: errln("Failed. No exception has been thrown for DOM -1 startDay +savings");
0947: } catch (IllegalArgumentException e) {
0948: logln("(c) " + e.getMessage());
0949: }
0950: try {
0951: zone = new SimpleTimeZone(0, "A", 0, 0, 0, 0, 0, -1, 0, 0,
0952: 1000);
0953: errln("Failed. No exception has been thrown for DOM -1 endDay +savings");
0954: } catch (IllegalArgumentException e) {
0955: logln("(d) " + e.getMessage());
0956: }
0957: // Make a valid constructor call for subsequent tests.
0958:
0959: zone = new SimpleTimeZone(0, "A", 0, 1, 0, 0, 0, 1, 0, 0);
0960:
0961: try {
0962: zone.setStartRule(0, -1, 0, 0);
0963: errln("Failed. No exception has been thrown for DOM -1 setStartRule +savings");
0964: } catch (IllegalArgumentException e) {
0965: logln("(e) " + e.getMessage());
0966: }
0967: try {
0968: zone.setStartRule(0, -1, 0);
0969: errln("Failed. No exception has been thrown for DOM -1 setStartRule");
0970: } catch (IllegalArgumentException e) {
0971: logln("(f) " + e.getMessage());
0972: }
0973: try {
0974: zone.setEndRule(0, -1, 0, 0);
0975: errln("Failed. No exception has been thrown for DOM -1 setEndRule +savings");
0976: } catch (IllegalArgumentException e) {
0977: logln("(g) " + e.getMessage());
0978: }
0979: try {
0980: zone.setEndRule(0, -1, 0);
0981: errln("Failed. No exception has been thrown for DOM -1 setEndRule");
0982: } catch (IllegalArgumentException e) {
0983: logln("(h) " + e.getMessage());
0984: }
0985:
0986: }
0987:
0988: /**
0989: * SimpleTimeZone.getOffset() throws IllegalArgumentException when to get
0990: * of 2/29/1996 (leap day).
0991: */
0992: public void Test4208960() {
0993: TimeZone tz = TimeZone.getTimeZone("PST");
0994: try {
0995: /*int offset =*/tz.getOffset(GregorianCalendar.AD, 1996,
0996: Calendar.FEBRUARY, 29, Calendar.THURSDAY, 0);
0997: //offset = 0;
0998: } catch (IllegalArgumentException e) {
0999: errln("FAILED: to get TimeZone.getOffset(2/29/96)");
1000: }
1001: try {
1002: /*int offset =*/tz.getOffset(GregorianCalendar.AD, 1997,
1003: Calendar.FEBRUARY, 29, Calendar.THURSDAY, 0);
1004: //offset = 0;
1005: warnln("FAILED: TimeZone.getOffset(2/29/97) expected to throw Exception.");
1006: } catch (IllegalArgumentException e) {
1007: logln("got IllegalArgumentException");
1008: }
1009: }
1010:
1011: /**
1012: * Test to see if DateFormat understands zone equivalency groups. It
1013: * might seem that this should be a DateFormat test, but it's really a
1014: * TimeZone test -- the changes to DateFormat are minor.
1015: *
1016: * We use two known, zones that are equivalent, where one zone has
1017: * localized name data, and the other doesn't, in some locale.
1018: */
1019: public void TestJ449() {
1020: // not used String str;
1021:
1022: // Modify the following three as necessary. The two IDs must
1023: // specify two zones in the same equivalency group. One must have
1024: // locale data in 'loc'; the other must not.
1025: String idWithLocaleData = "America/Los_Angeles";
1026: String idWithoutLocaleData = "PST"; // "US/Pacific";
1027: Locale loc = new Locale("en", "", "");
1028:
1029: TimeZone zoneWith = TimeZone.getTimeZone(idWithLocaleData);
1030: TimeZone zoneWithout = TimeZone
1031: .getTimeZone(idWithoutLocaleData);
1032: // Make sure we got valid zones
1033: if (!(zoneWith.getID().equals(idWithLocaleData) && zoneWithout
1034: .getID().equals(idWithoutLocaleData))) {
1035: warnln("Fail: Unable to create zones");
1036: } else {
1037: GregorianCalendar calWith = new GregorianCalendar(zoneWith);
1038: GregorianCalendar calWithout = new GregorianCalendar(
1039: zoneWithout);
1040: SimpleDateFormat fmt = new SimpleDateFormat(
1041: "MMM d yyyy hh:mm a zzz", loc);
1042: Date date = new Date(0L);
1043: fmt.setCalendar(calWith);
1044: String strWith = fmt.format(date);
1045: fmt.setCalendar(calWithout);
1046: String strWithout = fmt.format(date);
1047: if (strWith.equals(strWithout)) {
1048: logln("Ok: " + idWithLocaleData + " -> " + strWith
1049: + "; " + idWithoutLocaleData + " -> "
1050: + strWithout);
1051: } else {
1052: errln("FAIL: " + idWithLocaleData + " -> " + strWith
1053: + "; " + idWithoutLocaleData + " -> "
1054: + strWithout);
1055: }
1056: }
1057: }
1058:
1059: /**
1060: * getOffset returns wrong offset for days in early 20th century
1061: */
1062: public void TestJ5134() {
1063: GregorianCalendar testCal = (GregorianCalendar) Calendar
1064: .getInstance();
1065: TimeZone icuEastern = TimeZone.getTimeZone("America/New_York");
1066: testCal.setTimeZone(icuEastern);
1067: testCal.set(1900, Calendar.JANUARY, 1, 0, 0, 0);
1068: long time = testCal.getTimeInMillis();
1069:
1070: int offset = icuEastern.getOffset(time);
1071: if (offset != -18000000) {
1072: errln("FAIL: UTC offset in time zone America/New_York on Jan 1, 1900 -> "
1073: + offset);
1074: }
1075: boolean isDst = icuEastern.inDaylightTime(new Date(time));
1076: if (isDst) {
1077: errln("FAIL: DST is observed in time zone America/New_York on Jan 1, 1900");
1078: }
1079:
1080: //#ifndef FOUNDATION
1081: if (System.getProperty("java.vendor", "").startsWith("IBM")
1082: && System.getProperty("java.version", "").equals(
1083: "1.4.1")) {
1084: // IBM JDK 1.4.1 has a bug and fails to run this test case.
1085: return;
1086: }
1087: java.util.TimeZone jdkEastern = java.util.TimeZone
1088: .getTimeZone("America/New_York");
1089: // Compare offset and DST observation with JDK and ICU for 50 years since 1900
1090: testCal.add(Calendar.YEAR, 50);
1091: long endTime = testCal.getTimeInMillis();
1092: int jdkOffset;
1093: boolean isDstJdk;
1094: while (time < endTime) {
1095: offset = icuEastern.getOffset(time);
1096: jdkOffset = jdkEastern.getOffset(time);
1097: if (offset != jdkOffset) {
1098: errln("FAIL: Incompatible UTC offset -> JDK:"
1099: + jdkOffset + "/ICU:" + offset + " [" + time
1100: + "]");
1101: }
1102: Date d = new Date(time);
1103: isDst = icuEastern.inDaylightTime(d);
1104: isDstJdk = jdkEastern.inDaylightTime(d);
1105: if (isDst != isDstJdk) {
1106: errln("FAIL: Incompatible DST -> JDK:" + isDstJdk
1107: + "/ICU:" + isDst + " [" + time + "]");
1108: }
1109: time += 24 * 60 * 60 * 1000L; // increment 1 day
1110: }
1111: //#endif
1112: }
1113: }
1114:
1115: //eof
|