Class TimeZoneJDK
- java.lang.Object
-
- com.ibm.icu.util.TimeZone
-
- com.ibm.icu.impl.icuadapter.TimeZoneJDK
-
public class TimeZoneJDK extends TimeZone
TimeZoneJDK is an adapter class which wraps java.util.TimeZone and implements ICU4J TimeZone APIs.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.ibm.icu.util.TimeZone
TimeZone.SystemTimeZoneType
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
fIsFrozen
private java.util.Calendar
fJdkCal
private java.util.TimeZone
fJdkTz
private static long
serialVersionUID
-
Fields inherited from class com.ibm.icu.util.TimeZone
GENERIC_LOCATION, GMT_ZONE, LONG, LONG_GENERIC, LONG_GMT, SHORT, SHORT_COMMONLY_USED, SHORT_GENERIC, SHORT_GMT, TIMEZONE_ICU, TIMEZONE_JDK, UNKNOWN_ZONE, UNKNOWN_ZONE_ID
-
-
Constructor Summary
Constructors Modifier Constructor Description private
TimeZoneJDK(java.util.TimeZone jdkTz)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
clone()
Overrides clone.TimeZone
cloneAsThawed()
Provides for the clone operation.boolean
equals(java.lang.Object obj)
Overrides equals.TimeZone
freeze()
Freezes the object.java.lang.String
getDisplayName(boolean daylight, int style, ULocale locale)
Returns a name of this time zone suitable for presentation to the user in the specified locale.java.lang.String
getDisplayName(boolean daylight, int style, java.util.Locale locale)
Returns a name of this time zone suitable for presentation to the user in the specified locale.int
getDSTSavings()
Returns the amount of time to be added to local standard time to get local wall clock time.java.lang.String
getID()
Gets the ID of this time zone.int
getOffset(int era, int year, int month, int day, int dayOfWeek, int milliseconds)
Gets the time zone offset, for current date, modified in case of daylight savings.int
getOffset(long date)
Returns the offset of this time zone from UTC at the specified date.void
getOffset(long date, boolean local, int[] offsets)
Returns the time zone raw and GMT offset for the given moment in time.int
getRawOffset()
Gets unmodified offset, NOT modified in case of daylight savings.int
hashCode()
Overrides hashCode.boolean
hasSameRules(TimeZone other)
Returns true if this zone has the same rule and offset as another zone.boolean
inDaylightTime(java.util.Date date)
Queries if the given date is in daylight savings time in this time zone.boolean
isFrozen()
Determines whether the object has been frozen or not.boolean
observesDaylightTime()
Queries if this time zone is in daylight saving time or will observe daylight saving time at any future time.void
setID(java.lang.String ID)
Sets the time zone ID.void
setRawOffset(int offsetMillis)
Sets the base time zone offset to GMT.java.util.TimeZone
unwrap()
boolean
useDaylightTime()
Queries if this time zone uses daylight savings time.static TimeZone
wrap(java.util.TimeZone jdkTz)
-
Methods inherited from class com.ibm.icu.util.TimeZone
countEquivalentIDs, forLocaleOrDefault, forULocaleOrDefault, getAvailableIDs, getAvailableIDs, getAvailableIDs, getAvailableIDs, getCanonicalID, getCanonicalID, getDefault, getDefaultTimeZoneType, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getEquivalentID, getFrozenTimeZone, getIanaID, getIDForWindowsID, getRegion, getTimeZone, getTimeZone, getTZDataVersion, getWindowsID, setDefault, setDefaultTimeZoneType, setICUDefault
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
fJdkTz
private java.util.TimeZone fJdkTz
-
fJdkCal
private transient java.util.Calendar fJdkCal
-
fIsFrozen
private transient volatile boolean fIsFrozen
-
-
Method Detail
-
wrap
public static TimeZone wrap(java.util.TimeZone jdkTz)
-
unwrap
public java.util.TimeZone unwrap()
-
clone
public java.lang.Object clone()
Description copied from class:TimeZone
Overrides clone.
-
equals
public boolean equals(java.lang.Object obj)
Description copied from class:TimeZone
Overrides equals.
-
getDisplayName
public java.lang.String getDisplayName(boolean daylight, int style, java.util.Locale locale)
Description copied from class:TimeZone
Returns a name of this time zone suitable for presentation to the user in the specified locale. If the display name is not available for the locale, then this method returns a string in the localized GMT offset format such asGMT[+-]HH:mm
.- Overrides:
getDisplayName
in classTimeZone
- Parameters:
daylight
- if true, return the daylight savings name.style
- the output style of the display name. Valid styles areSHORT
,LONG
,SHORT_GENERIC
,LONG_GENERIC
,SHORT_GMT
,LONG_GMT
,SHORT_COMMONLY_USED
orGENERIC_LOCATION
.locale
- the locale in which to supply the display name.- Returns:
- the human-readable name of this time zone in the given locale or in the default locale if the given locale is not recognized.
-
getDisplayName
public java.lang.String getDisplayName(boolean daylight, int style, ULocale locale)
Description copied from class:TimeZone
Returns a name of this time zone suitable for presentation to the user in the specified locale. If the display name is not available for the locale, then this method returns a string in the localized GMT offset format such asGMT[+-]HH:mm
.- Overrides:
getDisplayName
in classTimeZone
- Parameters:
daylight
- if true, return the daylight savings name.style
- the output style of the display name. Valid styles areSHORT
,LONG
,SHORT_GENERIC
,LONG_GENERIC
,SHORT_GMT
,LONG_GMT
,SHORT_COMMONLY_USED
orGENERIC_LOCATION
.locale
- the locale in which to supply the display name.- Returns:
- the human-readable name of this time zone in the given locale or in the default locale if the given locale is not recognized.
-
getDSTSavings
public int getDSTSavings()
Description copied from class:TimeZone
Returns the amount of time to be added to local standard time to get local wall clock time.The default implementation always returns 3600000 milliseconds (i.e., one hour) if this time zone observes Daylight Saving Time. Otherwise, 0 (zero) is returned.
If an underlying TimeZone implementation subclass supports historical Daylight Saving Time changes, this method returns the known latest daylight saving value.
- Overrides:
getDSTSavings
in classTimeZone
- Returns:
- the amount of saving time in milliseconds
-
getID
public java.lang.String getID()
Description copied from class:TimeZone
Gets the ID of this time zone.
-
getOffset
public int getOffset(int era, int year, int month, int day, int dayOfWeek, int milliseconds)
Description copied from class:TimeZone
Gets the time zone offset, for current date, modified in case of daylight savings. This is the offset to add to UTC to get local time.- Specified by:
getOffset
in classTimeZone
- Parameters:
era
- the era of the given date.year
- the year in the given date.month
- the month in the given date. Month is 0-based. e.g., 0 for January.day
- the day-in-month of the given date.dayOfWeek
- the day-of-week of the given date.milliseconds
- the millis in day in standard local time.- Returns:
- the offset to add to GMT to get local time.
-
getOffset
public int getOffset(long date)
Description copied from class:TimeZone
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.- Overrides:
getOffset
in classTimeZone
- Parameters:
date
- the date represented in milliseconds since January 1, 1970 00:00:00 GMT- Returns:
- the amount of time in milliseconds to add to UTC to get local time.
- See Also:
Calendar.ZONE_OFFSET
,Calendar.DST_OFFSET
,TimeZone.getOffset(long, boolean, int[])
-
getOffset
public void getOffset(long date, boolean local, int[] offsets)
Description copied from class:TimeZone
Returns the time zone raw and GMT offset for the given moment in time. Upon return, local-millis = GMT-millis + rawOffset + dstOffset. All computations are performed in the proleptic Gregorian calendar. The default implementation in the TimeZone class delegates to the 8-argument getOffset().- Overrides:
getOffset
in classTimeZone
- Parameters:
date
- moment in time for which to return offsets, in units of milliseconds from January 1, 1970 0:00 GMT, either GMT time or local wall time, depending onlocal
.local
- if true,date
is local wall time; otherwise it is in GMT time.offsets
- output parameter to receive the raw offset, that is, the offset not including DST adjustments, in offsets[0], and the DST offset, that is, the offset to be added torawOffset
to obtain the total offset between local and GMT time, in offsets[1]. If DST is not in effect, the DST offset is zero; otherwise it is a positive value, typically one hour.
-
getRawOffset
public int getRawOffset()
Description copied from class:TimeZone
Gets unmodified offset, NOT modified in case of daylight savings. This is the offset to add to UTC to get local time.- Specified by:
getRawOffset
in classTimeZone
- Returns:
- the unmodified offset to add to UTC to get local time.
-
hashCode
public int hashCode()
Description copied from class:TimeZone
Overrides hashCode.
-
hasSameRules
public boolean hasSameRules(TimeZone other)
Description copied from class:TimeZone
Returns true if this zone has the same rule and offset as another zone. That is, if this zone differs only in ID, if at all. Returns false if the other zone is null.- Overrides:
hasSameRules
in classTimeZone
- Parameters:
other
- theTimeZone
object to be compared with- Returns:
- true if the other zone is not null and is the same as this one, with the possible exception of the ID
-
inDaylightTime
public boolean inDaylightTime(java.util.Date date)
Description copied from class:TimeZone
Queries if the given date is in daylight savings time in this time zone.- Specified by:
inDaylightTime
in classTimeZone
- Parameters:
date
- the given Date.- Returns:
- true if the given date is in daylight savings time, false, otherwise.
-
setID
public void setID(java.lang.String ID)
Description copied from class:TimeZone
Sets the time zone ID. This does not change any other data in the time zone object.
-
setRawOffset
public void setRawOffset(int offsetMillis)
Description copied from class:TimeZone
Sets the base time zone offset to GMT. This is the offset to add to UTC to get local time.- Specified by:
setRawOffset
in classTimeZone
- Parameters:
offsetMillis
- the given base time zone offset to GMT.
-
useDaylightTime
public boolean useDaylightTime()
Description copied from class:TimeZone
Queries if this time zone uses daylight savings time.- Specified by:
useDaylightTime
in classTimeZone
- Returns:
- true if this time zone uses daylight savings time,
false, otherwise.
Note:The default implementation of ICU TimeZone uses the tz database, which supports historic rule changes, for system time zones. With the implementation, there are time zones that used daylight savings time in the past, but no longer used currently. For example, Asia/Tokyo has never used daylight savings time since 1951. Most clients would expect that this method to return
false
for such case. The default implementation of this method returnstrue
when the time zone uses daylight savings time in the current (Gregorian) calendar year.
-
observesDaylightTime
public boolean observesDaylightTime()
Description copied from class:TimeZone
Queries if this time zone is in daylight saving time or will observe daylight saving time at any future time.The default implementation in this class returns
true
ifTimeZone.useDaylightTime()
orinDaylightTime(new Date())
returnstrue
.Note: This method was added for
TimeZone
compatibility support. TheTimeZone.useDaylightTime()
method only checks the last known rule(s), therefore it may return false even the zone observes daylight saving time currently.TimeZone
addedobservesDaylightTime()
to resolve the issue. In ICU,TimeZone.useDaylightTime()
works differently. The ICU implementation checks if the zone uses daylight saving time in the current calendar year. Therefore, it will never returnfalse
if daylight saving time is currently used.ICU's TimeZone subclass implementations override this method to support the same behavior with
TimeZone.observesDaylightTime()
. UnlikeTimeZone.useDaylightTime()
, the implementation does not take past daylight saving time into account, so that this method may returnfalse
even whenTimeZone.useDaylightTime()
returnstrue
.- Overrides:
observesDaylightTime
in classTimeZone
- Returns:
true
if this time zone is in daylight saving time or will observe daylight saving time at any future time.- See Also:
TimeZone.useDaylightTime()
-
isFrozen
public boolean isFrozen()
Description copied from class:TimeZone
Determines whether the object has been frozen or not.
-
cloneAsThawed
public TimeZone cloneAsThawed()
Description copied from class:TimeZone
Provides for the clone operation. Any clone is initially unfrozen.- Specified by:
cloneAsThawed
in interfaceFreezable<TimeZone>
- Overrides:
cloneAsThawed
in classTimeZone
-
-