ICU-2966 minimize dependency on historical zone behavior (make tests pass on JDK 1.3 and JDK 1.4)

X-SVN-Rev: 13435
This commit is contained in:
Alan Liu 2003-10-16 00:52:18 +00:00
parent 1353d4f063
commit d0b4433b9b
3 changed files with 33 additions and 19 deletions

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/calendar/AstroTest.java,v $
* $Date: 2003/10/02 20:50:57 $
* $Revision: 1.14 $
* $Date: 2003/10/16 00:49:58 $
* $Revision: 1.15 $
*
*****************************************************************************************
*/
@ -168,7 +168,16 @@ public class AstroTest extends TestFmwk {
logln("Sunrise/Sunset times for Toronto, Canada");
CalendarAstronomer astro = new CalendarAstronomer(-(79+25/60), 43+40/60);
TimeZone tz = TimeZone.getTimeZone("America/Montreal");
// As of ICU4J 2.8 the ICU4J time zones implement pass-through
// to the underlying JDK. Because of variation in the
// underlying JDKs, we have to use a fixed-offset
// SimpleTimeZone to get consistent behavior between JDKs.
// The offset we want is [-18000000, 3600000] (raw, dst).
// [aliu 10/15/03]
// TimeZone tz = TimeZone.getTimeZone("America/Montreal");
TimeZone tz = new SimpleTimeZone(-18000000 + 3600000, "Montreal(FIXED)");
GregorianCalendar cal = new GregorianCalendar(tz, Locale.US);
GregorianCalendar cal2 = new GregorianCalendar(tz, Locale.US);
@ -181,7 +190,7 @@ public class AstroTest extends TestFmwk {
DateFormat df = DateFormat.getTimeInstance(cal, DateFormat.MEDIUM, Locale.US);
DateFormat df2 = DateFormat.getDateTimeInstance(cal, DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.US);
DateFormat day = DateFormat.getDateInstance(cal, DateFormat.MEDIUM, Locale.US);
for (int i=0; i < 30; i++) {
astro.setDate(cal.getTime());

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/calendar/CalendarRegression.java,v $
* $Date: 2003/10/09 02:50:07 $
* $Revision: 1.19 $
* $Date: 2003/10/16 00:49:57 $
* $Revision: 1.20 $
*
*******************************************************************************
*/
@ -1801,7 +1801,7 @@ public class CalendarRegression extends com.ibm.icu.dev.test.TestFmwk {
Locale loc = Locale.US;
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
java.util.Calendar tempcal = java.util.Calendar.getInstance();
tempcal.set(2001 + 1900, Calendar.APRIL, 5, 17, 43, 53);
tempcal.set(2001, Calendar.APRIL, 5, 17, 43, 53);
Date date = tempcal.getTime();
Calendar cal = Calendar.getInstance(loc);
Object[] DATA = {
@ -1815,7 +1815,7 @@ public class CalendarRegression extends com.ibm.icu.dev.test.TestFmwk {
DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT, loc),
"DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT, loc)",
"Friday, April 5, 3901 5:43 PM",
"Thursday, April 5, 2001 5:43 PM",
DateFormat.getDateInstance(cal, DateFormat.SHORT, loc),
"DateFormat.getDateInstance(cal, DateFormat.SHORT, loc)",
@ -1827,15 +1827,15 @@ public class CalendarRegression extends com.ibm.icu.dev.test.TestFmwk {
DateFormat.getDateTimeInstance(cal, DateFormat.FULL, DateFormat.SHORT, loc),
"DateFormat.getDateTimeInstance(cal, DateFormat.FULL, DateFormat.SHORT, loc)",
"Friday, April 5, 3901 5:43 PM",
"Thursday, April 5, 2001 5:43 PM",
cal.getDateTimeFormat(DateFormat.SHORT, DateFormat.FULL, loc),
"cal.getDateTimeFormat(DateFormat.SHORT, DateFormat.FULL, loc)",
"4/5/01 5:43:53 PM PST",
"4/5/01 5:43:53 PM PDT",
cal.getDateTimeFormat(DateFormat.FULL, DateFormat.SHORT, loc),
"cal.getDateTimeFormat(DateFormat.FULL, DateFormat.SHORT, loc)",
"Friday, April 5, 3901 5:43 PM",
"Thursday, April 5, 2001 5:43 PM",
};
for (int i=0; i<DATA.length; i+=3) {
DateFormat df = (DateFormat) DATA[i];
@ -1899,4 +1899,4 @@ public class CalendarRegression extends com.ibm.icu.dev.test.TestFmwk {
}
}
//eof
//eof

View File

@ -4,8 +4,8 @@
* others. All Rights Reserved. *
*******************************************************************************
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/format/DateFormatTest.java,v $
* $Date: 2003/10/13 17:14:46 $
* $Revision: 1.20 $
* $Date: 2003/10/16 00:52:18 $
* $Revision: 1.21 $
*
*****************************************************************************************
*/
@ -140,10 +140,10 @@ public class DateFormatTest extends com.ibm.icu.dev.test.TestFmwk {
/*
* SimpleDateFormat(pattern, locale) Construct a SimpleDateDateFormat using
* the givening pattern, the locale and using the TimeZone.getDefault();
* the given pattern, the locale and using the TimeZone.getDefault();
* So it need to add the timezone offset on hour field.
* ps. the Method Calendar.getTime() used by SimpleDateFormat.parse() always
* return Date vaule with TimeZone.getDefault() [Richard/GCL]
* return Date value with TimeZone.getDefault() [Richard/GCL]
*/
TimeZone defaultTZ = TimeZone.getDefault();
@ -151,7 +151,8 @@ public class DateFormatTest extends com.ibm.icu.dev.test.TestFmwk {
int defaultOffset = defaultTZ.getRawOffset();
int PSTOffset = PST.getRawOffset();
int hour = 2 + (defaultOffset - PSTOffset) / (60*60*1000);
hour = (hour < 0) ? hour + 24 : hour;
// hour is the expected hour of day, in units of seconds
hour = ((hour < 0) ? hour + 24 : hour) * 60*60;
try {
Date d = fmt.parse(s);
Calendar cal = Calendar.getInstance();
@ -160,9 +161,13 @@ public class DateFormatTest extends com.ibm.icu.dev.test.TestFmwk {
hour += defaultTZ.inDaylightTime(d) ? 1 : 0;
logln(s + " P> " + ((DateFormat) fullFmt).format(d));
int hr = cal.get(Calendar.HOUR_OF_DAY);
// hr is the actual hour of day, in units of seconds
// adjust for DST
int hr = cal.get(Calendar.HOUR_OF_DAY) * 60*60 -
cal.get(Calendar.DST_OFFSET) / 1000;
if (hr != hour)
errln("FAIL: Should parse to hour " + hour);
errln("FAIL: Hour (-DST) = " + hr / (60*60.0)+
"; expected " + hour / (60*60.0));
} catch (ParseException e) {
errln("Parse Error:" + e.getMessage());
}