ICU-3467 add missing timezone API

X-SVN-Rev: 14149
This commit is contained in:
Doug Felt 2003-12-17 00:50:34 +00:00
parent c02c4bdcbf
commit 76f05cc785
2 changed files with 47 additions and 23 deletions

View file

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/SimpleDateFormat.java,v $
* $Date: 2003/12/13 00:30:55 $
* $Revision: 1.26 $
* $Date: 2003/12/17 00:50:33 $
* $Revision: 1.27 $
*
*****************************************************************************************
*/
@ -28,7 +28,6 @@ import java.util.Date;
import java.util.Hashtable;
import java.util.Locale;
import java.util.ResourceBundle;
import java.lang.reflect.Method;
/**
* <code>SimpleDateFormat</code> is a concrete class for formatting and
@ -1002,22 +1001,7 @@ public class SimpleDateFormat extends DateFormat {
cal.set(Calendar.ZONE_OFFSET, tz.getRawOffset());
int savings = 0;
if (j >= 3) {
// TODO: When JDK 1.3 support is dropped, change the following
// try/catch block to "savings = tz.getDSTSavings();".
// As of ICU 2.8 we support both 1.4 and 1.3. When 1.3
// support is dropped, we can call
// TimeZone.getDSTSavings() directly. Until then, we use
// reflection to call getDSTSavings() on either TimeZone
// or SimpleTimeZone. - Alan
try {
// The following works if getDSTSavings is declared in
// TimeZone (JDK 1.4) or SimpleTimeZone (JDK 1.3).
Method m = tz.getClass().getMethod("getDSTSavings", new Class[0]);
savings = ((Integer) m.invoke(tz, new Object[0])).intValue();
} catch (Exception e1) {
// todo: fix bug 3458, this code shold be on JDKTimeZone
}
savings = tz.getDSTSavings();
}
cal.set(Calendar.DST_OFFSET, savings);
return (start + formatData.zoneStrings[i][j].length());

View file

@ -116,6 +116,27 @@ abstract public class TimeZone implements Serializable, Cloneable {
abstract public int getOffset(int era, int year, int month, int day,
int dayOfWeek, int milliseconds);
/**
* Returns the offset of this time zone from UTC at the specified
* date. If Daylight Saving Time is in effect at the specified
* date, the offset value is adjusted with the amount of daylight
* saving.
*
* @param date the date represented in milliseconds since January 1, 1970 00:00:00 GMT
* @return the amount of time in milliseconds to add to UTC to get local time.
*
* @see Calendar#ZONE_OFFSET
* @see Calendar#DST_OFFSET
* @see #getOffset(long, boolean, int[])
* @draft ICU 2.8
*/
public int getOffset(long date) {
int[] result = new int[2];
getOffset(date, false, result);
return result[0]+result[1];
}
/**
* Returns the time zone raw and GMT offset for the given moment
* in time. Upon return, local-millis = GMT-millis + rawOffset +
@ -424,10 +445,7 @@ abstract public class TimeZone implements Serializable, Cloneable {
// they're small and cheap to create.
SimpleTimeZone tz;
if (daylight && useDaylightTime()) {
int savings = 3600000; // one hour
try {
savings = ((SimpleTimeZone) this).getDSTSavings();
} catch (ClassCastException e) {}
int savings = getDSTSavings();
tz = new SimpleTimeZone(getRawOffset(), getID(),
Calendar.JANUARY, 1, 0, 0,
Calendar.FEBRUARY, 1, 0, 0,
@ -442,6 +460,28 @@ abstract public class TimeZone implements Serializable, Cloneable {
return format.format(new Date(864000000L));
}
/**
* Returns the amount of time to be added to local standard time
* to get local wall clock time.
* <p>
* The default implementation always returns 3600000 milliseconds
* (i.e., one hour) if this time zone observes Daylight Saving
* Time. Otherwise, 0 (zero) is returned.
* <p>
* If an underlying TimeZone implementation subclass supports
* historical Daylight Saving Time changes, this method returns
* the known latest daylight saving value.
*
* @return the amount of saving time in milliseconds
* @draft ICU 2.8
*/
public int getDSTSavings() {
if (useDaylightTime()) {
return 3600000;
}
return 0;
}
/**
* Queries if this time zone uses daylight savings time.
* @return true if this time zone uses daylight savings time,