0001: /**
0002: *******************************************************************************
0003: * Copyright (C) 2000-2006, International Business Machines Corporation and *
0004: * others. All Rights Reserved. *
0005: *******************************************************************************
0006: */
0007:
0008: /**
0009: * @test 1.22 99/09/21
0010: * @bug 4028006 4044013 4096694 4107276 4107570 4112869 4130885
0011: * @summary test TimeZone
0012: * @build TimeZoneTest
0013: */package com.ibm.icu.dev.test.timezone;
0014:
0015: import com.ibm.icu.dev.test.*;
0016: import com.ibm.icu.impl.ICUResourceBundle;
0017: import com.ibm.icu.util.*;
0018: import com.ibm.icu.text.SimpleDateFormat;
0019:
0020: import java.io.ByteArrayInputStream;
0021: import java.io.ByteArrayOutputStream;
0022: import java.io.IOException;
0023: import java.io.ObjectInputStream;
0024: import java.io.ObjectOutputStream;
0025: import java.lang.reflect.InvocationTargetException;
0026: import java.util.Arrays;
0027: import java.util.Date;
0028: import java.util.Hashtable;
0029: import java.util.List;
0030: import java.util.Locale;
0031:
0032: public class TimeZoneTest extends TestFmwk {
0033: static final int millisPerHour = 3600000;
0034:
0035: public static void main(String[] args) throws Exception {
0036: new TimeZoneTest().run(args);
0037: }
0038:
0039: /**
0040: * NOTE: As of ICU 2.8, the mapping of 3-letter legacy aliases
0041: * to `real' Olson IDs is under control of the underlying JDK.
0042: * This test may fail on one JDK and pass on another; don't be
0043: * too concerned. Alan
0044: *
0045: * Bug 4130885
0046: * Certain short zone IDs, used since 1.1.x, are incorrect.
0047: *
0048: * The worst of these is:
0049: *
0050: * "CAT" (Central African Time) should be GMT+2:00, but instead returns a
0051: * zone at GMT-1:00. The zone at GMT-1:00 should be called EGT, CVT, EGST,
0052: * or AZOST, depending on which zone is meant, but in no case is it CAT.
0053: *
0054: * Other wrong zone IDs:
0055: *
0056: * ECT (European Central Time) GMT+1:00: ECT is Ecuador Time,
0057: * GMT-5:00. European Central time is abbreviated CEST.
0058: *
0059: * SST (Solomon Island Time) GMT+11:00. SST is actually Samoa Standard Time,
0060: * GMT-11:00. Solomon Island time is SBT.
0061: *
0062: * NST (New Zealand Time) GMT+12:00. NST is the abbreviation for
0063: * Newfoundland Standard Time, GMT-3:30. New Zealanders use NZST.
0064: *
0065: * AST (Alaska Standard Time) GMT-9:00. [This has already been noted in
0066: * another bug.] It should be "AKST". AST is Atlantic Standard Time,
0067: * GMT-4:00.
0068: *
0069: * PNT (Phoenix Time) GMT-7:00. PNT usually means Pitcairn Time,
0070: * GMT-8:30. There is no standard abbreviation for Phoenix time, as distinct
0071: * from MST with daylight savings.
0072: *
0073: * In addition to these problems, a number of zones are FAKE. That is, they
0074: * don't match what people use in the real world.
0075: *
0076: * FAKE zones:
0077: *
0078: * EET (should be EEST)
0079: * ART (should be EEST)
0080: * MET (should be IRST)
0081: * NET (should be AMST)
0082: * PLT (should be PKT)
0083: * BST (should be BDT)
0084: * VST (should be ICT)
0085: * CTT (should be CST) +
0086: * ACT (should be CST) +
0087: * AET (should be EST) +
0088: * MIT (should be WST) +
0089: * IET (should be EST) +
0090: * PRT (should be AST) +
0091: * CNT (should be NST)
0092: * AGT (should be ARST)
0093: * BET (should be EST) +
0094: *
0095: * + A zone with the correct name already exists and means something
0096: * else. E.g., EST usually indicates the US Eastern zone, so it cannot be
0097: * used for Brazil (BET).
0098: */
0099: public void TestShortZoneIDs() throws Exception {
0100:
0101: ZoneDescriptor[] JDK_116_REFERENCE_LIST = {
0102: new ZoneDescriptor("MIT", -660, false),
0103: new ZoneDescriptor("HST", -600, false),
0104: new ZoneDescriptor("AST", -540, true),
0105: new ZoneDescriptor("PST", -480, true),
0106: new ZoneDescriptor("PNT", -420, false),
0107: new ZoneDescriptor("MST", -420, false),// updated Aug 2003 aliu
0108: new ZoneDescriptor("CST", -360, true),
0109: new ZoneDescriptor("IET", -300, true), // updated Feb 2006 srl
0110: new ZoneDescriptor("EST", -300, false),// updated Aug 2003 aliu
0111: new ZoneDescriptor("PRT", -240, false),
0112: new ZoneDescriptor("CNT", -210, true),
0113: new ZoneDescriptor("AGT", -180, false),
0114: new ZoneDescriptor("BET", -180, true),
0115: // new ZoneDescriptor("CAT", -60, false), // Wrong:
0116: // As of bug 4130885, fix CAT (Central Africa)
0117: new ZoneDescriptor("CAT", 120, false), // Africa/Harare
0118: new ZoneDescriptor("GMT", 0, false),
0119: new ZoneDescriptor("UTC", 0, false),
0120: new ZoneDescriptor("ECT", 60, true),
0121: new ZoneDescriptor("ART", 120, true),
0122: new ZoneDescriptor("EET", 120, true),
0123: new ZoneDescriptor("EAT", 180, false),
0124: // new ZoneDescriptor("MET", 210, true),
0125: // This is a standard Unix zone, so don't remap it - Liu 3Jan01
0126: // new ZoneDescriptor("NET", 240, false);
0127: // As of bug 4191164, fix NET
0128: new ZoneDescriptor("NET", 240, true),
0129: // PLT behaves differently under different JDKs, so we don't check it
0130: // new ZoneDescriptor("PLT", 300, false), // updated Oct 2003 aliu
0131: new ZoneDescriptor("IST", 330, false),
0132: new ZoneDescriptor("BST", 360, false),
0133: new ZoneDescriptor("VST", 420, false),
0134: new ZoneDescriptor("CTT", 480, false), // updated Oct 2003 aliu
0135: new ZoneDescriptor("JST", 540, false),
0136: new ZoneDescriptor("ACT", 570, false), // updated Oct 2003 aliu
0137: new ZoneDescriptor("AET", 600, true),
0138: new ZoneDescriptor("SST", 660, false),
0139: // new ZoneDescriptor("NST", 720, false),
0140: // As of bug 4130885, fix NST (New Zealand)
0141: new ZoneDescriptor("NST", 720, true), // Pacific/Auckland
0142:
0143: // [3Jan01 Liu] Three of these zones have been updated.
0144: // The CTT and ACT zones just remap to Asia/Shanghai
0145: // and Australia/Darwin. Since those zones have changed,
0146: // I have updated the table. The MET zone used to be mapped
0147: // to Asia/Tehran but since MET is a standard Unix zone named
0148: // in the source data we no longer do this in icu or icu4j.
0149: };
0150:
0151: Hashtable hash = new Hashtable();
0152:
0153: String[] ids = TimeZone.getAvailableIDs();
0154: for (int i = 0; i < ids.length; ++i) {
0155: String id = ids[i];
0156: if (id.length() == 3) {
0157: hash.put(id, new ZoneDescriptor(TimeZone
0158: .getTimeZone(id)));
0159: }
0160: }
0161:
0162: for (int i = 0; i < JDK_116_REFERENCE_LIST.length; ++i) {
0163: ZoneDescriptor referenceZone = JDK_116_REFERENCE_LIST[i];
0164: ZoneDescriptor currentZone = (ZoneDescriptor) hash
0165: .get(referenceZone.getID());
0166: if (referenceZone.equals(currentZone)) {
0167: logln("ok " + referenceZone);
0168: } else {
0169: warnln("Fail: Expected " + referenceZone + "; got "
0170: + currentZone);
0171: }
0172: }
0173: }
0174:
0175: /**
0176: * A descriptor for a zone; used to regress the short zone IDs.
0177: */
0178: static class ZoneDescriptor {
0179: String id;
0180: int offset; // In minutes
0181: boolean daylight;
0182:
0183: ZoneDescriptor(TimeZone zone) {
0184: this .id = zone.getID();
0185: this .offset = zone.getRawOffset() / 60000;
0186: this .daylight = zone.useDaylightTime();
0187: }
0188:
0189: ZoneDescriptor(String id, int offset, boolean daylight) {
0190: this .id = id;
0191: this .offset = offset;
0192: this .daylight = daylight;
0193: }
0194:
0195: public String getID() {
0196: return id;
0197: }
0198:
0199: public boolean equals(Object o) {
0200: ZoneDescriptor that = (ZoneDescriptor) o;
0201: return that != null && id.equals(that.id)
0202: && offset == that.offset
0203: && daylight == that.daylight;
0204: }
0205:
0206: public String toString() {
0207: int min = offset;
0208: char sign = '+';
0209: if (min < 0) {
0210: sign = '-';
0211: min = -min;
0212: }
0213:
0214: return "Zone[\"" + id + "\", GMT" + sign + (min / 60) + ':'
0215: + (min % 60 < 10 ? "0" : "") + (min % 60) + ", "
0216: + (daylight ? "Daylight" : "Standard") + "]";
0217: }
0218:
0219: public static int compare(Object o1, Object o2) {
0220: ZoneDescriptor i1 = (ZoneDescriptor) o1;
0221: ZoneDescriptor i2 = (ZoneDescriptor) o2;
0222: if (i1.offset > i2.offset)
0223: return 1;
0224: if (i1.offset < i2.offset)
0225: return -1;
0226: if (i1.daylight && !i2.daylight)
0227: return 1;
0228: if (!i1.daylight && i2.daylight)
0229: return -1;
0230: return i1.id.compareTo(i2.id);
0231: }
0232: }
0233:
0234: static final String EXPECTED_CUSTOM_ID = "Custom";
0235:
0236: static final String formatMinutes(int min) {
0237: char sign = '+';
0238: if (min < 0) {
0239: sign = '-';
0240: min = -min;
0241: }
0242: int h = min / 60;
0243: min = min % 60;
0244: return "" + sign + (h < 10 ? "0" : "") + h + ":"
0245: + (min < 10 ? "0" : "") + min;
0246: }
0247:
0248: /**
0249: * As part of the VM fix (see CCC approved RFE 4028006, bug
0250: * 4044013), TimeZone.getTimeZone() has been modified to recognize
0251: * generic IDs of the form GMT[+-]hh:mm, GMT[+-]hhmm, and
0252: * GMT[+-]hh. Test this behavior here.
0253: *
0254: * Bug 4044013
0255: */
0256: public void TestCustomParse() {
0257: Object[] DATA = {
0258: // ID Expected offset in minutes
0259: "GMT",
0260: null,
0261: "GMT-YOUR.AD.HERE",
0262: null,
0263: // "GMT0", null, // ICU 3.6: An Olson zone IDThis is parsed by some JDKs (Sun 1.4.1), but not by others
0264: // "GMT+0", new Integer(0),// ICU 3.6: An Olson zone ID
0265: "GMT+1",
0266: new Integer(60),
0267: "GMT-0030",
0268: new Integer(-30),
0269: // Parsed in 1.3, parse failure in 1.4:
0270: //"GMT+15:99", new Integer(15*60+99),
0271: "GMT+", null, "GMT-", null, "GMT+0:", null, "GMT-:",
0272: null, "GMT+0010",
0273: new Integer(10), // Interpret this as 00:10
0274: "GMT-10",
0275: new Integer(-10 * 60),
0276: // Parsed in 1.3, parse failure in 1.4:
0277: //"GMT+30", new Integer(30),
0278: "GMT-3:30", new Integer(-(3 * 60 + 30)), "GMT-230",
0279: new Integer(-(2 * 60 + 30)), };
0280: for (int i = 0; i < DATA.length; i += 2) {
0281: String id = (String) DATA[i];
0282: Integer exp = (Integer) DATA[i + 1];
0283: TimeZone zone = TimeZone.getTimeZone(id);
0284: if (zone.getID().equals("GMT")) {
0285: logln(id + " -> generic GMT");
0286: // When TimeZone.getTimeZone() can't parse the id, it
0287: // returns GMT -- a dubious practice, but required for
0288: // backward compatibility.
0289: if (exp != null) {
0290: errln("Expected offset of "
0291: + formatMinutes(exp.intValue()) + " for "
0292: + id + ", got parse failure");
0293: }
0294: } else {
0295: int ioffset = zone.getRawOffset() / 60000;
0296: String offset = formatMinutes(ioffset);
0297: String genID = "GMT" + offset;
0298: logln(id + " -> " + zone.getID() + " " + genID);
0299: String gotID = zone.getID();
0300: if (exp == null) {
0301: errln("Expected parse failure for " + id
0302: + ", got offset of " + offset + ", id "
0303: + zone.getID());
0304: }
0305: // JDK 1.3 creates custom zones with the ID "Custom"
0306: // JDK 1.4 creates custom zones with IDs of the form "GMT+02:00"
0307: else if (ioffset != exp.intValue()
0308: || !(gotID.equals(EXPECTED_CUSTOM_ID) /*||
0309: gotID.equals(genID)*/)) {
0310: errln("Expected offset of "
0311: + formatMinutes(exp.intValue())
0312: + ", id Custom, for " + id
0313: + ", got offset of " + offset + ", id "
0314: + zone.getID());
0315: }
0316: }
0317: }
0318: }
0319:
0320: /**
0321: * Test the basic functionality of the getDisplayName() API.
0322: *
0323: * Bug 4112869
0324: * Bug 4028006
0325: *
0326: * See also API change request A41.
0327: *
0328: * 4/21/98 - make smarter, so the test works if the ext resources
0329: * are present or not.
0330: */
0331: public void TestDisplayName() {
0332: TimeZone zone = TimeZone.getTimeZone("PST");
0333: String name = zone.getDisplayName(Locale.ENGLISH);
0334: logln("PST->" + name);
0335:
0336: // dlf - we now (3.4.1) return generic time
0337: if (!name.equals("Pacific Time"))
0338: errln("Fail: Expected \"Pacific Time\", got " + name
0339: + " for " + zone);
0340:
0341: //*****************************************************************
0342: // THE FOLLOWING LINES MUST BE UPDATED IF THE LOCALE DATA CHANGES
0343: // THE FOLLOWING LINES MUST BE UPDATED IF THE LOCALE DATA CHANGES
0344: // THE FOLLOWING LINES MUST BE UPDATED IF THE LOCALE DATA CHANGES
0345: //*****************************************************************
0346:
0347: // todo: check to see whether we can test for all of pst, pdt, pt
0348: Object[] DATA = { new Boolean(false),
0349: new Integer(TimeZone.SHORT), "PST", new Boolean(true),
0350: new Integer(TimeZone.SHORT), "PDT", new Boolean(false),
0351: new Integer(TimeZone.LONG), "Pacific Standard Time",
0352: new Boolean(true), new Integer(TimeZone.LONG),
0353: "Pacific Daylight Time", };
0354:
0355: for (int i = 0; i < DATA.length; i += 3) {
0356: name = zone.getDisplayName(((Boolean) DATA[i])
0357: .booleanValue(),
0358: ((Integer) DATA[i + 1]).intValue(), Locale.ENGLISH);
0359: if (!name.equals(DATA[i + 2]))
0360: errln("Fail: Expected " + DATA[i + 2] + "; got " + name);
0361: }
0362:
0363: // Make sure that we don't display the DST name by constructing a fake
0364: // PST zone that has DST all year long.
0365: // dlf - this test is no longer relevant, we display generic time now
0366: // so the behavior of the timezone doesn't matter
0367: SimpleTimeZone zone2 = new SimpleTimeZone(0, "PST");
0368: zone2.setStartRule(Calendar.JANUARY, 1, 0);
0369: zone2.setEndRule(Calendar.DECEMBER, 31, 0);
0370: logln("Modified PST inDaylightTime->"
0371: + zone2.inDaylightTime(new Date()));
0372: name = zone2.getDisplayName(Locale.ENGLISH);
0373: logln("Modified PST->" + name);
0374: if (!name.equals("Pacific Time"))
0375: errln("Fail: Expected \"Pacific Time\"");
0376:
0377: // Make sure we get the default display format for Locales
0378: // with no display name data.
0379: Locale mt_MT = new Locale("mt", "MT");
0380: name = zone.getDisplayName(mt_MT);
0381: //*****************************************************************
0382: // THE FOLLOWING LINE MUST BE UPDATED IF THE LOCALE DATA CHANGES
0383: // THE FOLLOWING LINE MUST BE UPDATED IF THE LOCALE DATA CHANGES
0384: // THE FOLLOWING LINE MUST BE UPDATED IF THE LOCALE DATA CHANGES
0385: //*****************************************************************
0386: logln("PST(mt_MT)->" + name);
0387:
0388: // Now be smart -- check to see if zh resource is even present.
0389: // If not, we expect the en fallback behavior.
0390:
0391: // in icu4j 2.1 we know we have the zh_CN locale data, though it's incomplete
0392: // /"DateFormatZoneData",
0393: UResourceBundle enRB = UResourceBundle.getBundleInstance(
0394: ICUResourceBundle.ICU_BASE_NAME, Locale.ENGLISH);
0395: UResourceBundle mtRB = UResourceBundle.getBundleInstance(
0396: ICUResourceBundle.ICU_BASE_NAME, mt_MT);
0397: boolean noZH = enRB == mtRB;
0398:
0399: if (noZH) {
0400: logln("Warning: Not testing the mt_MT behavior because resource is absent");
0401: if (!name.equals("Pacific Standard Time"))
0402: errln("Fail: Expected Pacific Standard Time for PST in mt_MT but got ");
0403: }
0404: // dlf - we will use generic time, or if unavailable, GMT for standard time in the zone
0405: // - we now (3.4.1) have localizations for this zone, so change test string
0406: else if (!name.equals("Los Angeles (Stati Uniti)")
0407: && !name.equals("GMT-08:00")
0408: && !name.equals("GMT-8:00") && !name.equals("GMT-0800")
0409: && !name.equals("GMT-800")) {
0410:
0411: errln("Fail: got '"
0412: + name
0413: + "', expected GMT-08:00 or something similar\n"
0414: + "************************************************************\n"
0415: + "THE ABOVE FAILURE MAY JUST MEAN THE LOCALE DATA HAS CHANGED\n"
0416: + "************************************************************");
0417: }
0418:
0419: // Now try a non-existent zone
0420: zone2 = new SimpleTimeZone(90 * 60 * 1000, "xyzzy");
0421: name = zone2.getDisplayName(Locale.ENGLISH);
0422: logln("GMT+90min->" + name);
0423: if (!name.equals("GMT+01:30") && !name.equals("GMT+1:30")
0424: && !name.equals("GMT+0130") && !name.equals("GMT+130"))
0425: errln("Fail: Expected GMT+01:30 or something similar");
0426:
0427: // cover getDisplayName() - null arg
0428: ULocale save = ULocale.getDefault();
0429: ULocale.setDefault(ULocale.US);
0430: name = zone2.getDisplayName();
0431: logln("GMT+90min->" + name + "for default display locale");
0432: if (!name.equals("GMT+01:30") && !name.equals("GMT+1:30")
0433: && !name.equals("GMT+0130") && !name.equals("GMT+130"))
0434: errln("Fail: Expected GMT+01:30 or something similar");
0435: ULocale.setDefault(save);
0436: }
0437:
0438: public void TestDisplayName2() {
0439: // Date now = new Date();
0440: Date then = new Date(2005, 0, 1);
0441:
0442: String[] timezones = { "America/Chicago", "Europe/Moscow",
0443: "Europe/Rome", "Asia/Shanghai", "WET" };
0444: String[] locales = { "en", "fr", "de", "ja", "zh_TW", "zh_Hans" };
0445: for (int j = 0; j < locales.length; ++j) {
0446: ULocale locale = new ULocale(locales[j]);
0447: for (int i = 0; i < timezones.length; ++i) {
0448: TimeZone tz = TimeZone.getTimeZone(timezones[i]);
0449: String displayName0 = tz.getDisplayName(locale); // doesn't work???
0450: SimpleDateFormat dt = new SimpleDateFormat("vvvv",
0451: locale);
0452: dt.setTimeZone(tz);
0453: String displayName1 = dt.format(then); // date value _does_ matter if we fallback to GMT
0454: logln(locale.getDisplayName() + ", " + tz.getID()
0455: + ": " + displayName0);
0456: if (!displayName1.equals(displayName0)) {
0457: errln(locale.getDisplayName() + ", " + tz.getID()
0458: + ": expected " + displayName1
0459: + " but got: " + displayName0);
0460: }
0461: }
0462: }
0463: }
0464:
0465: public void TestGenericAPI() {
0466: String id = "NewGMT";
0467: int offset = 12345;
0468:
0469: SimpleTimeZone zone = new SimpleTimeZone(offset, id);
0470: if (zone.useDaylightTime())
0471: errln("FAIL: useDaylightTime should return false");
0472:
0473: TimeZone zoneclone = (TimeZone) zone.clone();
0474: if (!zoneclone.equals(zone))
0475: errln("FAIL: clone or operator== failed");
0476: zoneclone.setID("abc");
0477: if (zoneclone.equals(zone))
0478: errln("FAIL: clone or operator!= failed");
0479: // delete zoneclone;
0480:
0481: zoneclone = (TimeZone) zone.clone();
0482: if (!zoneclone.equals(zone))
0483: errln("FAIL: clone or operator== failed");
0484: zoneclone.setRawOffset(45678);
0485: if (zoneclone.equals(zone))
0486: errln("FAIL: clone or operator!= failed");
0487:
0488: // C++ only
0489: /*
0490: SimpleTimeZone copy(*zone);
0491: if (!(copy == *zone)) errln("FAIL: copy constructor or operator== failed");
0492: copy = *(SimpleTimeZone*)zoneclone;
0493: if (!(copy == *zoneclone)) errln("FAIL: assignment operator or operator== failed");
0494: */
0495:
0496: TimeZone saveDefault = TimeZone.getDefault();
0497: TimeZone.setDefault(zone);
0498: TimeZone defaultzone = TimeZone.getDefault();
0499: if (defaultzone == zone)
0500: errln("FAIL: Default object is identical, not clone");
0501: if (!defaultzone.equals(zone))
0502: errln("FAIL: Default object is not equal");
0503: TimeZone.setDefault(saveDefault);
0504: // delete defaultzone;
0505: // delete zoneclone;
0506:
0507: // // ICU 2.6 Coverage
0508: // logln(zone.toString());
0509: // logln(zone.getDisplayName());
0510: // SimpleTimeZoneAdapter stza = new SimpleTimeZoneAdapter((SimpleTimeZone) TimeZone.getTimeZone("GMT"));
0511: // stza.setID("Foo");
0512: // if (stza.hasSameRules(java.util.TimeZone.getTimeZone("GMT"))) {
0513: // errln("FAIL: SimpleTimeZoneAdapter.hasSameRules");
0514: // }
0515: // stza.setRawOffset(3000);
0516: // offset = stza.getOffset(GregorianCalendar.BC, 2001, Calendar.DECEMBER,
0517: // 25, Calendar.TUESDAY, 12*60*60*1000);
0518: // if (offset != 3000) {
0519: // errln("FAIL: SimpleTimeZoneAdapter.getOffset");
0520: // }
0521: // SimpleTimeZoneAdapter dup = (SimpleTimeZoneAdapter) stza.clone();
0522: // if (stza.hashCode() != dup.hashCode()) {
0523: // errln("FAIL: SimpleTimeZoneAdapter.hashCode");
0524: // }
0525: // if (!stza.equals(dup)) {
0526: // errln("FAIL: SimpleTimeZoneAdapter.equals");
0527: // }
0528: // logln(stza.toString());
0529: }
0530:
0531: public void TestRuleAPI() {
0532: // ErrorCode status = ZERO_ERROR;
0533:
0534: int offset = (int) (60 * 60 * 1000 * 1.75); // Pick a weird offset
0535: SimpleTimeZone zone = new SimpleTimeZone(offset, "TestZone");
0536: if (zone.useDaylightTime())
0537: errln("FAIL: useDaylightTime should return false");
0538:
0539: // Establish our expected transition times. Do this with a non-DST
0540: // calendar with the (above) declared local offset.
0541: GregorianCalendar gc = new GregorianCalendar(zone);
0542: gc.clear();
0543: gc.set(1990, Calendar.MARCH, 1);
0544: long marchOneStd = gc.getTime().getTime(); // Local Std time midnight
0545: gc.clear();
0546: gc.set(1990, Calendar.JULY, 1);
0547: long julyOneStd = gc.getTime().getTime(); // Local Std time midnight
0548:
0549: // Starting and ending hours, WALL TIME
0550: int startHour = (int) (2.25 * 3600000);
0551: int endHour = (int) (3.5 * 3600000);
0552:
0553: zone.setStartRule(Calendar.MARCH, 1, 0, startHour);
0554: zone.setEndRule(Calendar.JULY, 1, 0, endHour);
0555:
0556: gc = new GregorianCalendar(zone);
0557: // if (failure(status, "new GregorianCalendar")) return;
0558:
0559: long marchOne = marchOneStd + startHour;
0560: long julyOne = julyOneStd + endHour - 3600000; // Adjust from wall to Std time
0561:
0562: long expMarchOne = 636251400000L;
0563: if (marchOne != expMarchOne) {
0564: errln("FAIL: Expected start computed as " + marchOne
0565: + " = " + new Date(marchOne));
0566: logln(" Should be " + expMarchOne
0567: + " = " + new Date(expMarchOne));
0568: }
0569:
0570: long expJulyOne = 646793100000L;
0571: if (julyOne != expJulyOne) {
0572: errln("FAIL: Expected start computed as " + julyOne + " = "
0573: + new Date(julyOne));
0574: logln(" Should be " + expJulyOne
0575: + " = " + new Date(expJulyOne));
0576: }
0577:
0578: Calendar cal1 = Calendar.getInstance();
0579: cal1.set(1990, Calendar.JANUARY, 1);
0580: Calendar cal2 = Calendar.getInstance();
0581: cal2.set(1990, Calendar.JUNE, 1);
0582: _testUsingBinarySearch(zone, cal1.getTimeInMillis(), cal2
0583: .getTimeInMillis(), marchOne);
0584: cal1.set(1990, Calendar.JUNE, 1);
0585: cal2.set(1990, Calendar.DECEMBER, 31);
0586: _testUsingBinarySearch(zone, cal1.getTimeInMillis(), cal2
0587: .getTimeInMillis(), julyOne);
0588:
0589: if (zone.inDaylightTime(new Date(marchOne - 1000))
0590: || !zone.inDaylightTime(new Date(marchOne)))
0591: errln("FAIL: Start rule broken");
0592: if (!zone.inDaylightTime(new Date(julyOne - 1000))
0593: || zone.inDaylightTime(new Date(julyOne)))
0594: errln("FAIL: End rule broken");
0595:
0596: zone.setStartYear(1991);
0597: if (zone.inDaylightTime(new Date(marchOne))
0598: || zone.inDaylightTime(new Date(julyOne - 1000)))
0599: errln("FAIL: Start year broken");
0600:
0601: // failure(status, "TestRuleAPI");
0602: // delete gc;
0603: // delete zone;
0604: }
0605:
0606: void _testUsingBinarySearch(SimpleTimeZone tz, long min, long max,
0607: long expectedBoundary) {
0608: // ErrorCode status = ZERO_ERROR;
0609: boolean startsInDST = tz.inDaylightTime(new Date(min));
0610: // if (failure(status, "SimpleTimeZone::inDaylightTime")) return;
0611: if (tz.inDaylightTime(new Date(max)) == startsInDST) {
0612: logln("Error: inDaylightTime(" + new Date(max) + ") != "
0613: + (!startsInDST));
0614: return;
0615: }
0616: // if (failure(status, "SimpleTimeZone::inDaylightTime")) return;
0617: while ((max - min) > INTERVAL) {
0618: long mid = (min + max) / 2;
0619: if (tz.inDaylightTime(new Date(mid)) == startsInDST) {
0620: min = mid;
0621: } else {
0622: max = mid;
0623: }
0624: // if (failure(status, "SimpleTimeZone::inDaylightTime")) return;
0625: }
0626: logln("Binary Search Before: " + min + " = " + new Date(min));
0627: logln("Binary Search After: " + max + " = " + new Date(max));
0628: long mindelta = expectedBoundary - min;
0629: // not used long maxdelta = max - expectedBoundary;
0630: if (mindelta >= 0 && mindelta <= INTERVAL && mindelta >= 0
0631: && mindelta <= INTERVAL)
0632: logln("PASS: Expected bdry: " + expectedBoundary + " = "
0633: + new Date(expectedBoundary));
0634: else
0635: errln("FAIL: Expected bdry: " + expectedBoundary + " = "
0636: + new Date(expectedBoundary));
0637: }
0638:
0639: static final int INTERVAL = 100;
0640:
0641: // Bug 006; verify the offset for a specific zone.
0642: public void TestPRTOffset() {
0643: TimeZone tz = TimeZone.getTimeZone("PRT");
0644: if (tz == null) {
0645: errln("FAIL: TimeZone(PRT) is null");
0646: } else {
0647: if (tz.getRawOffset() != (-4 * millisPerHour))
0648: warnln("FAIL: Offset for PRT should be -4, got "
0649: + tz.getRawOffset() / (double) millisPerHour);
0650: }
0651:
0652: }
0653:
0654: // Test various calls
0655: public void TestVariousAPI518() {
0656: TimeZone time_zone = TimeZone.getTimeZone("PST");
0657: Calendar cal = Calendar.getInstance();
0658: cal.set(1997, Calendar.APRIL, 30);
0659: Date d = cal.getTime();
0660:
0661: logln("The timezone is " + time_zone.getID());
0662:
0663: if (time_zone.inDaylightTime(d) != true)
0664: errln("FAIL: inDaylightTime returned false");
0665:
0666: if (time_zone.useDaylightTime() != true)
0667: errln("FAIL: useDaylightTime returned false");
0668:
0669: if (time_zone.getRawOffset() != -8 * millisPerHour)
0670: errln("FAIL: getRawOffset returned wrong value");
0671:
0672: GregorianCalendar gc = new GregorianCalendar();
0673: gc.setTime(d);
0674: if (time_zone.getOffset(GregorianCalendar.AD, gc
0675: .get(GregorianCalendar.YEAR), gc
0676: .get(GregorianCalendar.MONTH), gc
0677: .get(GregorianCalendar.DAY_OF_MONTH), gc
0678: .get(GregorianCalendar.DAY_OF_WEEK), 0) != -7
0679: * millisPerHour)
0680: errln("FAIL: getOffset returned wrong value");
0681: }
0682:
0683: // Test getAvailableID API
0684: public void TestGetAvailableIDs913() {
0685: StringBuffer buf = new StringBuffer(
0686: "TimeZone.getAvailableIDs() = { ");
0687: String[] s = TimeZone.getAvailableIDs();
0688: for (int i = 0; i < s.length; ++i) {
0689: if (i > 0)
0690: buf.append(", ");
0691: buf.append(s[i]);
0692: }
0693: buf.append(" };");
0694: logln(buf.toString());
0695:
0696: buf.setLength(0);
0697: buf.append("TimeZone.getAvailableIDs(GMT+02:00) = { ");
0698: s = TimeZone.getAvailableIDs(+2 * 60 * 60 * 1000);
0699: for (int i = 0; i < s.length; ++i) {
0700: if (i > 0)
0701: buf.append(", ");
0702: buf.append(s[i]);
0703: }
0704: buf.append(" };");
0705: logln(buf.toString());
0706:
0707: TimeZone tz = TimeZone.getTimeZone("PST");
0708: if (tz != null)
0709: logln("getTimeZone(PST) = " + tz.getID());
0710: else
0711: errln("FAIL: getTimeZone(PST) = null");
0712:
0713: tz = TimeZone.getTimeZone("America/Los_Angeles");
0714: if (tz != null)
0715: logln("getTimeZone(America/Los_Angeles) = " + tz.getID());
0716: else
0717: errln("FAIL: getTimeZone(PST) = null");
0718:
0719: // Bug 4096694
0720: tz = TimeZone.getTimeZone("NON_EXISTENT");
0721: if (tz == null)
0722: errln("FAIL: getTimeZone(NON_EXISTENT) = null");
0723: else if (!tz.getID().equals("GMT"))
0724: errln("FAIL: getTimeZone(NON_EXISTENT) = " + tz.getID());
0725: }
0726:
0727: /**
0728: * Bug 4107276
0729: */
0730: public void TestDSTSavings() {
0731: // It might be better to find a way to integrate this test into the main TimeZone
0732: // tests above, but I don't have time to figure out how to do this (or if it's
0733: // even really a good idea). Let's consider that a future. --rtg 1/27/98
0734: SimpleTimeZone tz = new SimpleTimeZone(-5 * millisPerHour,
0735: "dstSavingsTest", Calendar.MARCH, 1, 0, 0,
0736: Calendar.SEPTEMBER, 1, 0, 0,
0737: (int) (0.5 * millisPerHour));
0738:
0739: if (tz.getRawOffset() != -5 * millisPerHour)
0740: errln("Got back a raw offset of "
0741: + (tz.getRawOffset() / millisPerHour)
0742: + " hours instead of -5 hours.");
0743: if (!tz.useDaylightTime())
0744: errln("Test time zone should use DST but claims it doesn't.");
0745: if (tz.getDSTSavings() != 0.5 * millisPerHour)
0746: errln("Set DST offset to 0.5 hour, but got back "
0747: + (tz.getDSTSavings() / millisPerHour)
0748: + " hours instead.");
0749:
0750: int offset = tz.getOffset(GregorianCalendar.AD, 1998,
0751: Calendar.JANUARY, 1, Calendar.THURSDAY,
0752: 10 * millisPerHour);
0753: if (offset != -5 * millisPerHour)
0754: errln("The offset for 10 AM, 1/1/98 should have been -5 hours, but we got "
0755: + (offset / millisPerHour) + " hours.");
0756:
0757: offset = tz.getOffset(GregorianCalendar.AD, 1998,
0758: Calendar.JUNE, 1, Calendar.MONDAY, 10 * millisPerHour);
0759: if (offset != -4.5 * millisPerHour)
0760: errln("The offset for 10 AM, 6/1/98 should have been -4.5 hours, but we got "
0761: + (offset / millisPerHour) + " hours.");
0762:
0763: tz.setDSTSavings(millisPerHour);
0764: offset = tz.getOffset(GregorianCalendar.AD, 1998,
0765: Calendar.JANUARY, 1, Calendar.THURSDAY,
0766: 10 * millisPerHour);
0767: if (offset != -5 * millisPerHour)
0768: errln("The offset for 10 AM, 1/1/98 should have been -5 hours, but we got "
0769: + (offset / millisPerHour) + " hours.");
0770:
0771: offset = tz.getOffset(GregorianCalendar.AD, 1998,
0772: Calendar.JUNE, 1, Calendar.MONDAY, 10 * millisPerHour);
0773: if (offset != -4 * millisPerHour)
0774: errln("The offset for 10 AM, 6/1/98 (with a 1-hour DST offset) should have been -4 hours, but we got "
0775: + (offset / millisPerHour) + " hours.");
0776: }
0777:
0778: /**
0779: * Bug 4107570
0780: */
0781: public void TestAlternateRules() {
0782: // Like TestDSTSavings, this test should probably be integrated somehow with the main
0783: // test at the top of this class, but I didn't have time to figure out how to do that.
0784: // --rtg 1/28/98
0785:
0786: SimpleTimeZone tz = new SimpleTimeZone(-5 * millisPerHour,
0787: "alternateRuleTest");
0788:
0789: // test the day-of-month API
0790: tz.setStartRule(Calendar.MARCH, 10, 12 * millisPerHour);
0791: tz.setEndRule(Calendar.OCTOBER, 20, 12 * millisPerHour);
0792:
0793: int offset = tz.getOffset(GregorianCalendar.AD, 1998,
0794: Calendar.MARCH, 5, Calendar.THURSDAY,
0795: 10 * millisPerHour);
0796: if (offset != -5 * millisPerHour)
0797: errln("The offset for 10AM, 3/5/98 should have been -5 hours, but we got "
0798: + (offset / millisPerHour) + " hours.");
0799:
0800: offset = tz
0801: .getOffset(GregorianCalendar.AD, 1998, Calendar.MARCH,
0802: 15, Calendar.SUNDAY, 10 * millisPerHour);
0803: if (offset != -4 * millisPerHour)
0804: errln("The offset for 10AM, 3/15/98 should have been -4 hours, but we got "
0805: + (offset / millisPerHour) + " hours.");
0806:
0807: offset = tz.getOffset(GregorianCalendar.AD, 1998,
0808: Calendar.OCTOBER, 15, Calendar.THURSDAY,
0809: 10 * millisPerHour);
0810: if (offset != -4 * millisPerHour)
0811: errln("The offset for 10AM, 10/15/98 should have been -4 hours, but we got "
0812: + (offset / millisPerHour) + " hours.");
0813:
0814: offset = tz.getOffset(GregorianCalendar.AD, 1998,
0815: Calendar.OCTOBER, 25, Calendar.SUNDAY,
0816: 10 * millisPerHour);
0817: if (offset != -5 * millisPerHour)
0818: errln("The offset for 10AM, 10/25/98 should have been -5 hours, but we got "
0819: + (offset / millisPerHour) + " hours.");
0820:
0821: // test the day-of-week-after-day-in-month API
0822: tz.setStartRule(Calendar.MARCH, 10, Calendar.FRIDAY,
0823: 12 * millisPerHour, true);
0824: tz.setEndRule(Calendar.OCTOBER, 20, Calendar.FRIDAY,
0825: 12 * millisPerHour, false);
0826:
0827: offset = tz.getOffset(GregorianCalendar.AD, 1998,
0828: Calendar.MARCH, 11, Calendar.WEDNESDAY,
0829: 10 * millisPerHour);
0830: if (offset != -5 * millisPerHour)
0831: errln("The offset for 10AM, 3/11/98 should have been -5 hours, but we got "
0832: + (offset / millisPerHour) + " hours.");
0833:
0834: offset = tz.getOffset(GregorianCalendar.AD, 1998,
0835: Calendar.MARCH, 14, Calendar.SATURDAY,
0836: 10 * millisPerHour);
0837: if (offset != -4 * millisPerHour)
0838: errln("The offset for 10AM, 3/14/98 should have been -4 hours, but we got "
0839: + (offset / millisPerHour) + " hours.");
0840:
0841: offset = tz.getOffset(GregorianCalendar.AD, 1998,
0842: Calendar.OCTOBER, 15, Calendar.THURSDAY,
0843: 10 * millisPerHour);
0844: if (offset != -4 * millisPerHour)
0845: errln("The offset for 10AM, 10/15/98 should have been -4 hours, but we got "
0846: + (offset / millisPerHour) + " hours.");
0847:
0848: offset = tz.getOffset(GregorianCalendar.AD, 1998,
0849: Calendar.OCTOBER, 17, Calendar.SATURDAY,
0850: 10 * millisPerHour);
0851: if (offset != -5 * millisPerHour)
0852: errln("The offset for 10AM, 10/17/98 should have been -5 hours, but we got "
0853: + (offset / millisPerHour) + " hours.");
0854: }
0855:
0856: public void TestEquivalencyGroups() {
0857: String id = "America/Los_Angeles";
0858: int n = TimeZone.countEquivalentIDs(id);
0859: if (n < 2) {
0860: errln("FAIL: countEquivalentIDs(" + id + ") returned " + n
0861: + ", expected >= 2");
0862: }
0863: for (int i = 0; i < n; ++i) {
0864: String s = TimeZone.getEquivalentID(id, i);
0865: if (s.length() == 0) {
0866: errln("FAIL: getEquivalentID(" + id + ", " + i
0867: + ") returned \"" + s + "\", expected valid ID");
0868: } else {
0869: logln("" + i + ":" + s);
0870: }
0871: }
0872: }
0873:
0874: public void TestCountries() {
0875: // Make sure America/Los_Angeles is in the "US" group, and
0876: // Asia/Tokyo isn't. Vice versa for the "JP" group.
0877:
0878: String[] s = TimeZone.getAvailableIDs("US");
0879: boolean la = false, tokyo = false;
0880: String laZone = "America/Los_Angeles", tokyoZone = "Asia/Tokyo";
0881:
0882: for (int i = 0; i < s.length; ++i) {
0883: if (s[i].equals(laZone)) {
0884: la = true;
0885: }
0886: if (s[i].equals(tokyoZone)) {
0887: tokyo = true;
0888: }
0889: }
0890: if (!la) {
0891: errln("FAIL: " + laZone + " in US = " + la);
0892: }
0893: if (tokyo) {
0894: errln("FAIL: " + tokyoZone + " in US = " + tokyo);
0895: }
0896: s = TimeZone.getAvailableIDs("JP");
0897: la = false;
0898: tokyo = false;
0899:
0900: for (int i = 0; i < s.length; ++i) {
0901: if (s[i].equals(laZone)) {
0902: la = true;
0903: }
0904: if (s[i].equals(tokyoZone)) {
0905: tokyo = true;
0906: }
0907: }
0908: if (la) {
0909: errln("FAIL: " + laZone + " in JP = " + la);
0910: }
0911: if (!tokyo) {
0912: errln("FAIL: " + tokyoZone + " in JP = " + tokyo);
0913: }
0914: }
0915:
0916: public void TestFractionalDST() {
0917: String tzName = "Australia/Lord_Howe"; // 30 min offset
0918: java.util.TimeZone tz_java = java.util.TimeZone
0919: .getTimeZone(tzName);
0920: int dst_java = 0;
0921: try {
0922: // hack so test compiles and runs in both JDK 1.3 and JDK 1.4
0923: final Object[] args = new Object[0];
0924: final Class[] argtypes = new Class[0];
0925: java.lang.reflect.Method m = tz_java.getClass().getMethod(
0926: "getDSTSavings", argtypes);
0927: dst_java = ((Integer) m.invoke(tz_java, args)).intValue();
0928: if (dst_java <= 0 || dst_java >= 3600000) { // didn't get the fractional time zone we wanted
0929: errln("didn't get fractional time zone!");
0930: }
0931: } catch (NoSuchMethodException e) {
0932: // see JDKTimeZone for the reason for this code
0933: dst_java = 3600000;
0934: } catch (IllegalAccessException e) {
0935: // see JDKTimeZone for the reason for this code
0936: errln(e.getMessage());
0937: dst_java = 3600000;
0938: } catch (InvocationTargetException e) {
0939: // see JDKTimeZone for the reason for this code
0940: errln(e.getMessage());
0941: dst_java = 3600000;
0942: } catch (SecurityException e) {
0943: warnln(e.getMessage());
0944: return;
0945: }
0946:
0947: com.ibm.icu.util.TimeZone tz_icu = com.ibm.icu.util.TimeZone
0948: .getTimeZone(tzName);
0949: int dst_icu = tz_icu.getDSTSavings();
0950:
0951: if (dst_java != dst_icu) {
0952: warnln("java reports dst savings of " + dst_java
0953: + " but icu reports " + dst_icu + " for tz "
0954: + tz_icu.getID());
0955: } else {
0956: logln("both java and icu report dst savings of " + dst_java
0957: + " for tz " + tz_icu.getID());
0958: }
0959: }
0960:
0961: public void TestGetOffsetDate() {
0962: Calendar cal = Calendar.getInstance();
0963: cal.set(1997, Calendar.JANUARY, 30);
0964: long date = cal.getTimeInMillis();
0965:
0966: TimeZone tz_icu = TimeZone.getTimeZone("America/Los_Angeles");
0967: int offset = tz_icu.getOffset(date);
0968: if (offset != -28800000) {
0969: errln("expected offset -28800000, got: " + offset);
0970: }
0971:
0972: cal.set(1997, Calendar.JULY, 30);
0973: date = cal.getTimeInMillis();
0974: offset = tz_icu.getOffset(date);
0975: if (offset != -25200000) {
0976: errln("expected offset -25200000, got: " + offset);
0977: }
0978: }
0979:
0980: // jb4484
0981: public void TestSimpleTimeZoneSerialization() {
0982: SimpleTimeZone stz0 = new SimpleTimeZone(32400000, "MyTimeZone");
0983: SimpleTimeZone stz1 = new SimpleTimeZone(32400000, "Asia/Tokyo");
0984: SimpleTimeZone stz2 = new SimpleTimeZone(32400000, "Asia/Tokyo");
0985: stz2.setRawOffset(0);
0986: SimpleTimeZone stz3 = new SimpleTimeZone(32400000, "Asia/Tokyo");
0987: stz3.setStartYear(100);
0988: SimpleTimeZone stz4 = new SimpleTimeZone(32400000, "Asia/Tokyo");
0989: stz4.setStartYear(1000);
0990: stz4.setDSTSavings(1800000);
0991: stz4.setStartRule(3, 4, 180000);
0992: stz4.setEndRule(6, 3, 4, 360000);
0993: SimpleTimeZone stz5 = new SimpleTimeZone(32400000, "Asia/Tokyo");
0994: stz5.setStartRule(2, 3, 4, 360000);
0995: stz5.setEndRule(6, 3, 4, 360000);
0996:
0997: SimpleTimeZone[] stzs = { stz0, stz1, stz2, stz3, stz4, stz5, };
0998:
0999: for (int i = 0; i < stzs.length; ++i) {
1000: SimpleTimeZone stz = stzs[i];
1001: try {
1002: ByteArrayOutputStream baos = new ByteArrayOutputStream();
1003: ObjectOutputStream oos = new ObjectOutputStream(baos);
1004: oos.writeObject(stz);
1005: oos.close();
1006: byte[] bytes = baos.toByteArray();
1007: logln("id: " + stz.getID() + " length: " + bytes.length);
1008:
1009: ByteArrayInputStream bais = new ByteArrayInputStream(
1010: bytes);
1011: ObjectInputStream ois = new ObjectInputStream(bais);
1012:
1013: SimpleTimeZone stzDeserialized = (SimpleTimeZone) ois
1014: .readObject();
1015: ois.close();
1016:
1017: assertEquals("time zones", stz, stzDeserialized);
1018: } catch (ClassCastException cce) {
1019: cce.printStackTrace();
1020: errln("could not deserialize SimpleTimeZone");
1021: } catch (IOException ioe) {
1022: errln(ioe.getMessage());
1023: } catch (ClassNotFoundException cnfe) {
1024: errln(cnfe.getMessage());
1025: }
1026: }
1027: }
1028:
1029: // jb4175
1030: /* Generated by org.unicode.cldr.tool.CountItems */
1031: private static final String[] timeZoneTestNames = {
1032: "America/Argentina/Buenos_Aires", "America/Buenos_Aires",
1033: "America/Argentina/Catamarca", "America/Catamarca",
1034: "America/Argentina/Cordoba", "America/Cordoba",
1035: "America/Argentina/Jujuy", "America/Jujuy",
1036: "America/Argentina/Mendoza", "America/Mendoza",
1037: "America/Atka", "America/Adak", "America/Ensenada",
1038: "America/Tijuana", "America/Fort_Wayne",
1039: "America/Indianapolis", "America/Indiana/Indianapolis",
1040: "America/Indianapolis", "America/Kentucky/Louisville",
1041: "America/Louisville", "America/Knox_IN",
1042: "America/Indiana/Knox", "America/Porto_Acre",
1043: "America/Rio_Branco", "America/Rosario", "America/Cordoba",
1044: "America/Virgin", "America/St_Thomas", "Asia/Ashkhabad",
1045: "Asia/Ashgabat", "Asia/Chungking", "Asia/Chongqing",
1046: "Asia/Dacca", "Asia/Dhaka", "Asia/Istanbul",
1047: "Europe/Istanbul", "Asia/Macao", "Asia/Macau",
1048: "Asia/Tel_Aviv", "Asia/Jerusalem", "Asia/Thimbu",
1049: "Asia/Thimphu", "Asia/Ujung_Pandang", "Asia/Makassar",
1050: "Asia/Ulan_Bator", "Asia/Ulaanbaatar", "Australia/ACT",
1051: "Australia/Sydney", "Australia/Canberra",
1052: "Australia/Sydney", "Australia/LHI", "Australia/Lord_Howe",
1053: "Australia/NSW", "Australia/Sydney", "Australia/North",
1054: "Australia/Darwin", "Australia/Queensland",
1055: "Australia/Brisbane", "Australia/South",
1056: "Australia/Adelaide", "Australia/Tasmania",
1057: "Australia/Hobart", "Australia/Victoria",
1058: "Australia/Melbourne", "Australia/West", "Australia/Perth",
1059: "Australia/Yancowinna", "Australia/Broken_Hill",
1060: "Brazil/Acre", "America/Rio_Branco", "Brazil/DeNoronha",
1061: "America/Noronha", "Brazil/East", "America/Sao_Paulo",
1062: "Brazil/West", "America/Manaus", "CST6CDT",
1063: "America/Chicago", "Canada/Atlantic", "America/Halifax",
1064: "Canada/Central", "America/Winnipeg",
1065: "Canada/East-Saskatchewan", "America/Regina",
1066: "Canada/Eastern", "America/Toronto", "Canada/Mountain",
1067: "America/Edmonton", "Canada/Newfoundland",
1068: "America/St_Johns", "Canada/Pacific", "America/Vancouver",
1069: "Canada/Saskatchewan", "America/Regina", "Canada/Yukon",
1070: "America/Whitehorse", "Chile/Continental",
1071: "America/Santiago", "Chile/EasterIsland", "Pacific/Easter",
1072: "Cuba", "America/Havana", "EST", "America/Indianapolis",
1073: "EST5EDT", "America/New_York", "Egypt", "Africa/Cairo",
1074: "Eire", "Europe/Dublin", "Etc/GMT+0", "Etc/GMT",
1075: "Etc/GMT-0", "Etc/GMT", "Etc/GMT0", "Etc/GMT",
1076: "Etc/Greenwich", "Etc/GMT", "Etc/UCT", "Etc/GMT",
1077: "Etc/UTC", "Etc/GMT", "Etc/Universal", "Etc/GMT",
1078: "Etc/Zulu", "Etc/GMT", "Europe/Nicosia", "Asia/Nicosia",
1079: "Europe/Tiraspol", "Europe/Chisinau", "GB",
1080: "Europe/London", "GB-Eire", "Europe/London", "GMT",
1081: "Etc/GMT", "GMT+0", "Etc/GMT", "GMT-0", "Etc/GMT", "GMT0",
1082: "Etc/GMT", "Greenwich", "Etc/GMT", "HST",
1083: "Pacific/Honolulu", "Hongkong", "Asia/Hong_Kong",
1084: "Iceland", "Atlantic/Reykjavik", "Iran", "Asia/Tehran",
1085: "Israel", "Asia/Jerusalem", "Jamaica", "America/Jamaica",
1086: "Japan", "Asia/Tokyo", "Kwajalein", "Pacific/Kwajalein",
1087: "Libya", "Africa/Tripoli", "MST", "America/Phoenix",
1088: "MST7MDT", "America/Denver", "Mexico/BajaNorte",
1089: "America/Tijuana", "Mexico/BajaSur", "America/Mazatlan",
1090: "Mexico/General", "America/Mexico_City", "NZ",
1091: "Pacific/Auckland", "NZ-CHAT", "Pacific/Chatham", "Navajo",
1092: "America/Shiprock", /* fixed from Mark's original */
1093: "PRC", "Asia/Shanghai", "PST8PDT", "America/Los_Angeles",
1094: "Pacific/Samoa", "Pacific/Pago_Pago", "Poland",
1095: "Europe/Warsaw", "Portugal", "Europe/Lisbon", "ROC",
1096: "Asia/Taipei", "ROK", "Asia/Seoul", "Singapore",
1097: "Asia/Singapore", "SystemV/AST4", "America/Puerto_Rico",
1098: "SystemV/AST4ADT", "America/Halifax", "SystemV/CST6",
1099: "America/Regina", "SystemV/CST6CDT", "America/Chicago",
1100: "SystemV/EST5", "America/Indianapolis", "SystemV/EST5EDT",
1101: "America/New_York", "SystemV/HST10", "Pacific/Honolulu",
1102: "SystemV/MST7", "America/Phoenix", "SystemV/MST7MDT",
1103: "America/Denver", "SystemV/PST8", "Pacific/Pitcairn",
1104: "SystemV/PST8PDT", "America/Los_Angeles", "SystemV/YST9",
1105: "Pacific/Gambier", "SystemV/YST9YDT", "America/Anchorage",
1106: "Turkey", "Europe/Istanbul", "UCT", "Etc/GMT", "US/Alaska",
1107: "America/Anchorage", "US/Aleutian", "America/Adak",
1108: "US/Arizona", "America/Phoenix", "US/Central",
1109: "America/Chicago", "US/East-Indiana",
1110: "America/Indianapolis", "US/Eastern", "America/New_York",
1111: "US/Hawaii", "Pacific/Honolulu", "US/Indiana-Starke",
1112: "America/Indiana/Knox", "US/Michigan", "America/Detroit",
1113: "US/Mountain", "America/Denver", "US/Pacific",
1114: "America/Los_Angeles", "US/Pacific-New",
1115: "America/Los_Angeles", "US/Samoa", "Pacific/Pago_Pago",
1116: "UTC", "Etc/GMT", "Universal", "Etc/GMT", "W-SU",
1117: "Europe/Moscow", "Zulu", "Etc/GMT", };
1118:
1119: public void TestOddTimeZoneNames() {
1120: for (int i = 0; i < timeZoneTestNames.length; i += 2) {
1121: String funkyName = timeZoneTestNames[i];
1122: String correctName = timeZoneTestNames[i + 1];
1123:
1124: TimeZone ftz = TimeZone.getTimeZone(funkyName);
1125: TimeZone ctz = TimeZone.getTimeZone(correctName);
1126:
1127: String fdn = ftz.getDisplayName();
1128: long fro = ftz.getRawOffset();
1129: long fds = ftz.getDSTSavings();
1130: boolean fdy = ftz.useDaylightTime();
1131:
1132: String cdn = ctz.getDisplayName();
1133: long cro = ctz.getRawOffset();
1134: long cds = ctz.getDSTSavings();
1135: boolean cdy = ctz.useDaylightTime();
1136:
1137: if (!fdn.equals(cdn)) {
1138: logln("display name (" + funkyName + ", " + correctName
1139: + ") expected: " + cdn + " but got: " + fdn);
1140: } else if (fro != cro) {
1141: logln("offset (" + funkyName + ", " + correctName
1142: + ") expected: " + cro + " but got: " + fro);
1143: } else if (fds != cds) {
1144: logln("daylight (" + funkyName + ", " + correctName
1145: + ") expected: " + cds + " but got: " + fds);
1146: } else if (fdy != cdy) {
1147: logln("uses daylight (" + funkyName + ", "
1148: + correctName + ") expected: " + cdy
1149: + " but got: " + fdy);
1150: } else {
1151: // no error, assume we're referencing the same internal java object
1152: }
1153: }
1154: }
1155:
1156: public void TestCoverage() {
1157: class StubTimeZone extends TimeZone {
1158: public int getOffset(int era, int year, int month, int day,
1159: int dayOfWeek, int milliseconds) {
1160: return 0;
1161: }
1162:
1163: public void setRawOffset(int offsetMillis) {
1164: }
1165:
1166: public int getRawOffset() {
1167: return 0;
1168: }
1169:
1170: public boolean useDaylightTime() {
1171: return false;
1172: }
1173:
1174: public boolean inDaylightTime(Date date) {
1175: return false;
1176: }
1177: }
1178: StubTimeZone stub = new StubTimeZone();
1179: StubTimeZone stub2 = (StubTimeZone) stub.clone();
1180: if (stub.getDSTSavings() != 0) {
1181: errln("TimeZone.getDSTSavings() should return 0");
1182: }
1183: if (!stub.hasSameRules(stub2)) {
1184: errln("TimeZone.clone() object should hasSameRules");
1185:
1186: }
1187: }
1188:
1189: public void TestMark() {
1190: String tzid = "America/Argentina/ComodRivadavia";
1191: TimeZone tz = TimeZone.getTimeZone(tzid);
1192: int offset = tz.getOffset(new Date().getTime());
1193: logln(tzid + ":\t" + offset);
1194: List list = Arrays.asList(TimeZone.getAvailableIDs());
1195: if (!list.contains(tzid)) {
1196: errln("Could create the time zone but it is not in getAvailableIDs");
1197: }
1198: }
1199:
1200: public void TestZoneMeta() {
1201: java.util.TimeZone save = java.util.TimeZone.getDefault();
1202: java.util.TimeZone newZone = java.util.TimeZone
1203: .getTimeZone("GMT-08:00");
1204: com.ibm.icu.util.TimeZone.setDefault(null);
1205: java.util.TimeZone.setDefault(newZone);
1206: SimpleTimeZone zone = new SimpleTimeZone(0, "GMT");
1207: com.ibm.icu.util.TimeZone defaultZone = com.ibm.icu.util.TimeZone
1208: .getDefault();
1209: if (defaultZone == null) {
1210: errln("TimeZone.getDefault() failed for GMT-08:00");
1211: }
1212: if (zone == null) {
1213: errln("SimpleTimeZone(0, GMT-08:00) failed for GMT-08:00");
1214: }
1215: //reset
1216: java.util.TimeZone.setDefault(save);
1217: }
1218: }
1219:
1220: //eof
|