Top Description Fields Constructors Methods
com.ibm.icu.impl

public Class OlsonTimeZone

extends BasicTimeZone
Class Inheritance
Imports
java.io.IOException, .ObjectInputStream, java.util.Arrays, .Date, .MissingResourceException, com.ibm.icu.util.AnnualTimeZoneRule, .BasicTimeZone, .Calendar, .DateTimeRule, .GregorianCalendar, .InitialTimeZoneRule, .SimpleTimeZone, .TimeArrayTimeZoneRule, .TimeZone, .TimeZoneRule, .TimeZoneTransition, .UResourceBundle

A time zone based on the Olson tz database. Olson time zones change behavior over time. The raw offset, rules, presence or absence of daylight savings time, and even the daylight savings amount can all vary. This class uses a resource bundle named "zoneinfo". Zoneinfo is a table containing different kinds of resources. In several places, zones are referred to using integers. A zone's integer is a number from 0..n-1, where n is the number of zones, with the zones sorted in lexicographic order. 1. Zones. These have keys corresponding to the Olson IDs, e.g., "Asia/Shanghai". Each resource describes the behavior of the given zone. Zones come in two different formats. a. Zone (table). A zone is a table resource contains several type of resources below: - typeOffsets:intvector (Required) Sets of UTC raw/dst offset pairs in seconds. Entries at 2n represents raw offset and 2n+1 represents dst offset paired with the raw offset at 2n. The very first pair represents the initial zone offset (before the first transition) always. - trans:intvector (Optional) List of transition times represented by 32bit seconds from the epoch (1970-01-01T00:00Z) in ascending order. - transPre32/transPost32:intvector (Optional) List of transition times before/after 32bit minimum seconds. Each time is represented by a pair of 32bit integer. - typeMap:bin (Optional) Array of bytes representing the mapping between each transition time (transPre32/trans/transPost32) and its corresponding offset data (typeOffsets). - finalRule:string (Optional) If a recurrent transition rule is applicable to a zone forever after the final transition time, finalRule represents the rule in Rules data. - finalRaw:int (Optional) When finalRule is available, finalRaw is required and specifies the raw (base) offset of the rule. - finalYear:int (Optional) When finalRule is available, finalYear is required and specifies the start year of the rule. - links:intvector (Optional) When this zone data is shared with other zones, links specifies all zones including the zone itself. Each zone is referenced by integer index. b. Link (int, length 1). A link zone is an int resource. The integer is the zone number of the target zone. The key of this resource is an alternate name for the target zone. This data is corresponding to Link data in the tz database. 2. Rules. These have keys corresponding to the Olson rule IDs, with an underscore prepended, e.g., "_EU". Each resource describes the behavior of the given rule using an intvector, containing the onset list, the cessation list, and the DST savings. The onset and cessation lists consist of the month, dowim, dow, time, and time mode. The end result is that the 11 integers describing the rule can be passed directly into the SimpleTimeZone 13-argument constructor (the other two arguments will be the raw offset, taken from the complex zone element 5, and the ID string, which is not used), with the times and the DST savings multiplied by 1000 to scale from seconds to milliseconds. 3. Regions. An array specifies mapping between zones and regions. Each item is either a 2-letter ISO country code or "001" (UN M.49 - World). This data is generated from "zone.tab" in the tz database.

Field Summary

Modifier and TypeField and Description
private volatile String
canonicalID

The canonical ID of this zone.

private static final int
private static final boolean
private double
finalStartMillis

For date >= finalStartMillis, the finalZone will be used.

private int
finalStartYear

For year >= finalStartYear, the finalZone will be used.

private SimpleTimeZone
finalZone

A SimpleTimeZone that governs the behavior for years >= finalYear.

private transient SimpleTimeZone
private transient TimeZoneTransition
private transient TimeZoneTransition
private transient int
private transient TimeArrayTimeZoneRule[]
private transient InitialTimeZoneRule
private transient volatile boolean
private static final int
private static final int
private int
pack-priv static final long
private int
transitionCount

Number of transitions, 0..~370

private transient boolean
private long[]
transitionTimes64

Time of each transition in seconds from 1970 epoch.

private int
typeCount

Number of types, 1..255

private byte[]
typeMapData

Type description data, consisting of transitionCount uint8_t type indices (from 0..typeCount-1).

private int[]
typeOffsets

Offset from GMT in seconds for each type.

private static final String
Inherited from com.ibm.icu.util.BasicTimeZone:
FORMER_LATTER_MASKLOCAL_DSTLOCAL_FORMERLOCAL_LATTERLOCAL_STDSTD_DST_MASK

Constructor Summary

AccessConstructor and Description
public
OlsonTimeZone(UResourceBundle
the top-level zoneinfo resource bundle. This is used to lookup the rule that res may refer to, if there is one.
top
,
UResourceBundle
the resource bundle of the zone to be constructed
res
,
String
time zone ID
id
)

Construct from a resource bundle

public

Method Summary

Modifier and TypeMethod and Description
public Object
clone()

Overrides com.ibm.icu.util.TimeZone.clone.

Overrides clone.
public TimeZone
private void
private void
constructEmpty()

Construct a GMT+0 zone with no transitions.

private int
dstOffsetAt(int transIdx)

public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides com.ibm.icu.util.TimeZone.equals.

Overrides equals.
public TimeZone
public String
getCanonicalID()

Returns the canonical ID of this system time zone

public int
getDSTSavings()

Overrides com.ibm.icu.util.TimeZone.getDSTSavings.

TimeZone API Returns the amount of time to be added to local standard time to get local wall clock time.
private void
getHistoricalOffset(long date, boolean local, int NonExistingTimeOpt, int DuplicatedTimeOpt, int[] offsets)

private int
getInt(byte val)

public TimeZoneTransition
getNextTransition(long
The base time.
base
,
boolean
Whether the base time is inclusive or not.
inclusive
)

Implements abstract com.ibm.icu.util.BasicTimeZone.getNextTransition.

ICU

public int
getOffset(int
the era of the given date.
era
,
int
the year in the given date.
year
,
int
the month in the given date. Month is 0-based. e.g., 0 for January.
month
,
int
the day-in-month of the given date.
day
,
int
the day-of-week of the given date.
dayOfWeek
,
int
the millis in day in standard local time.
milliseconds
)

Implements abstract com.ibm.icu.util.TimeZone.getOffset.

Gets the time zone offset, for current date, modified in case of daylight savings.
public int
getOffset(int era, int year, int month, int dom, int dow, int millis, int monthLength)

TimeZone API.

public void
getOffset(long
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 on local.
date
,
boolean
if true, date is local wall time; otherwise it is in GMT time.
local
,
int[]
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 to rawOffset 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.
offsets
)

Overrides com.ibm.icu.util.TimeZone.getOffset.

TimeZone API.
public void
getOffsetFromLocal(long date, BasicTimeZone.LocalOption nonExistingTimeOpt, BasicTimeZone.LocalOption duplicatedTimeOpt, int[] offsets)

Overrides com.ibm.icu.util.BasicTimeZone.getOffsetFromLocal.

ICU

public TimeZoneTransition
getPreviousTransition(long
The base time.
base
,
boolean
Whether the base time is inclusive or not.
inclusive
)

Implements abstract com.ibm.icu.util.BasicTimeZone.getPreviousTransition.

ICU

public int
getRawOffset()

Implements abstract com.ibm.icu.util.TimeZone.getRawOffset.

Gets unmodified offset, NOT modified in case of daylight savings.
public TimeZoneRule[]
public int
hashCode()

Overrides com.ibm.icu.util.TimeZone.hashCode.

Overrides hashCode.
public boolean
hasSameRules(TimeZone
the TimeZone object to be compared with
other
)

Overrides com.ibm.icu.util.TimeZone.hasSameRules.

Returns true if this zone has the same rule and offset as another zone.
public boolean
inDaylightTime(Date
the given Date.
date
)

Implements abstract com.ibm.icu.util.TimeZone.inDaylightTime.

Queries if the given date is in daylight savings time in this time zone.
private int
private int
private synchronized void
public boolean
isFrozen()

Overrides com.ibm.icu.util.TimeZone.isFrozen.

Implements com.ibm.icu.util.Freezable.isFrozen.

Determines whether the object has been frozen or not.
private static UResourceBundle
public boolean
observesDaylightTime()

Overrides com.ibm.icu.util.TimeZone.observesDaylightTime.

Queries if this time zone is in daylight saving time or will observe daylight saving time at any future time.
private int
rawOffsetAt(int transIdx)

private void
public void
setID(String
the new time zone ID.
id
)

Overrides com.ibm.icu.util.TimeZone.setID.

Sets the time zone ID. This does not change any other data in the time zone object.
public void
setRawOffset(int
the given base time zone offset to GMT.
offsetMillis
)

Implements abstract com.ibm.icu.util.TimeZone.setRawOffset.

Sets the base time zone offset to GMT.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public boolean
useDaylightTime()

Implements abstract com.ibm.icu.util.TimeZone.useDaylightTime.

Queries if this time zone uses daylight savings time.
private int
zoneOffsetAt(int transIdx)

Inherited from com.ibm.icu.util.BasicTimeZone:
getLocalOptionValuegetSimpleTimeZoneRulesNeargetTimeZoneRuleshasEquivalentTransitionshasEquivalentTransitions

Field Detail

canonicalIDback to summary
private volatile String canonicalID

The canonical ID of this zone. Initialized when getCanonicalID() is invoked first time, or setID(String) is called.

currentSerialVersionback to summary
private static final int currentSerialVersion
DEBUGback to summary
private static final boolean DEBUG
finalStartMillisback to summary
private double finalStartMillis

For date >= finalStartMillis, the finalZone will be used.

finalStartYearback to summary
private int finalStartYear

For year >= finalStartYear, the finalZone will be used.

finalZoneback to summary
private SimpleTimeZone finalZone

A SimpleTimeZone that governs the behavior for years >= finalYear. If and only if finalYear == INT32_MAX then finalZone == 0.

finalZoneWithStartYearback to summary
private transient SimpleTimeZone finalZoneWithStartYear
firstFinalTZTransitionback to summary
private transient TimeZoneTransition firstFinalTZTransition
firstTZTransitionback to summary
private transient TimeZoneTransition firstTZTransition
firstTZTransitionIdxback to summary
private transient int firstTZTransitionIdx
historicRulesback to summary
private transient TimeArrayTimeZoneRule[] historicRules
initialRuleback to summary
private transient InitialTimeZoneRule initialRule
isFrozenback to summary
private transient volatile boolean isFrozen
MAX_OFFSET_SECONDSback to summary
private static final int MAX_OFFSET_SECONDS
SECONDS_PER_DAYback to summary
private static final int SECONDS_PER_DAY
serialVersionOnStreamback to summary
private int serialVersionOnStream
serialVersionUIDback to summary
pack-priv static final long serialVersionUID

Hides com.ibm.icu.util.BasicTimeZone.serialVersionUID.

transitionCountback to summary
private int transitionCount

Number of transitions, 0..~370

transitionRulesInitializedback to summary
private transient boolean transitionRulesInitialized
transitionTimes64back to summary
private long[] transitionTimes64

Time of each transition in seconds from 1970 epoch.

typeCountback to summary
private int typeCount

Number of types, 1..255

typeMapDataback to summary
private byte[] typeMapData

Type description data, consisting of transitionCount uint8_t type indices (from 0..typeCount-1). Length is equal to transitionCount

typeOffsetsback to summary
private int[] typeOffsets

Offset from GMT in seconds for each type. Length is equal to typeCount

ZONEINFORESback to summary
private static final String ZONEINFORES

Constructor Detail

OlsonTimeZoneback to summary
public OlsonTimeZone(UResourceBundle top, UResourceBundle res, String id)

Construct from a resource bundle

Parameters
top:UResourceBundle

the top-level zoneinfo resource bundle. This is used to lookup the rule that res may refer to, if there is one.

res:UResourceBundle

the resource bundle of the zone to be constructed

id:String

time zone ID

OlsonTimeZoneback to summary
public OlsonTimeZone(String id)

Method Detail

cloneback to summary
public Object clone()

Overrides com.ibm.icu.util.TimeZone.clone.

Doc from com.ibm.icu.util.TimeZone.clone.

Overrides clone.

Returns:Object

Doc from java.lang.Object.clone.

a clone of this instance.

Annotations
@Override
cloneAsThawedback to summary
public TimeZone cloneAsThawed()

Overrides com.ibm.icu.util.TimeZone.cloneAsThawed.

Implements com.ibm.icu.util.Freezable.cloneAsThawed.

Doc from com.ibm.icu.util.TimeZone.cloneAsThawed.

Provides for the clone operation. Any clone is initially unfrozen.

Annotations
@Override
constructback to summary
private void construct(UResourceBundle top, UResourceBundle res, String id)
constructEmptyback to summary
private void constructEmpty()

Construct a GMT+0 zone with no transitions. This is done when a constructor fails so the resultant object is well-behaved.

dstOffsetAtback to summary
private int dstOffsetAt(int transIdx)
equalsback to summary
public boolean equals(Object obj)

Overrides com.ibm.icu.util.TimeZone.equals.

Doc from com.ibm.icu.util.TimeZone.equals.

Overrides equals.

Parameters
obj:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
freezeback to summary
public TimeZone freeze()

Overrides com.ibm.icu.util.TimeZone.freeze.

Implements com.ibm.icu.util.Freezable.freeze.

Doc from com.ibm.icu.util.TimeZone.freeze.

Freezes the object.

Returns:TimeZone

Doc from com.ibm.icu.util.Freezable.freeze.

the object itself.

Annotations
@Override
getCanonicalIDback to summary
public String getCanonicalID()

Returns the canonical ID of this system time zone

getDSTSavingsback to summary
public int getDSTSavings()

Overrides com.ibm.icu.util.TimeZone.getDSTSavings.

TimeZone API Returns the amount of time to be added to local standard time to get local wall clock time.

Returns:int

Doc from com.ibm.icu.util.TimeZone.getDSTSavings.

the amount of saving time in milliseconds

Annotations
@Override
getHistoricalOffsetback to summary
private void getHistoricalOffset(long date, boolean local, int NonExistingTimeOpt, int DuplicatedTimeOpt, int[] offsets)
getIntback to summary
private int getInt(byte val)
getNextTransitionback to summary
public TimeZoneTransition getNextTransition(long base, boolean inclusive)

Implements abstract com.ibm.icu.util.BasicTimeZone.getNextTransition.

Doc from com.ibm.icu.util.BasicTimeZone.getNextTransition.

ICU

Returns the first time zone transition after the base time.

Example code:{@. jcite com.ibm.icu.samples.util.timezone.BasicTimeZoneExample:---getNextTransitionExample}

Parameters
base:long

The base time.

inclusive:boolean

Whether the base time is inclusive or not.

Returns:TimeZoneTransition

A Date holding the first time zone transition time after the given base time, or null if no time zone transitions are available after the base time.

Annotations
@Override
getOffsetback to summary
public int getOffset(int era, int year, int month, int day, int dayOfWeek, int milliseconds)

Implements abstract com.ibm.icu.util.TimeZone.getOffset.

Doc from com.ibm.icu.util.TimeZone.getOffset.

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.

Parameters
era:int

the era of the given date.

year:int

the year in the given date.

month:int

the month in the given date. Month is 0-based. e.g., 0 for January.

day:int

the day-in-month of the given date.

dayOfWeek:int

the day-of-week of the given date.

milliseconds:int

the millis in day in standard local time.

Returns:int

the offset to add to GMT to get local time.

Annotations
@Override
getOffsetback to summary
public int getOffset(int era, int year, int month, int dom, int dow, int millis, int monthLength)

TimeZone API.

getOffsetback to summary
public void getOffset(long date, boolean local, int[] offsets)

Overrides com.ibm.icu.util.TimeZone.getOffset.

TimeZone API.

Parameters
date:long

Doc from com.ibm.icu.util.TimeZone.getOffset.

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 on local.

local:boolean

Doc from com.ibm.icu.util.TimeZone.getOffset.

if true, date is local wall time; otherwise it is in GMT time.

offsets:int[]

Doc from com.ibm.icu.util.TimeZone.getOffset.

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 to rawOffset 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.

Annotations
@Override
getOffsetFromLocalback to summary
public void getOffsetFromLocal(long date, BasicTimeZone.LocalOption nonExistingTimeOpt, BasicTimeZone.LocalOption duplicatedTimeOpt, int[] offsets)

Overrides com.ibm.icu.util.BasicTimeZone.getOffsetFromLocal.

Doc from com.ibm.icu.util.BasicTimeZone.getOffsetFromLocal.

ICU

Returns time zone offsets from local wall time.
Annotations
@Override
getPreviousTransitionback to summary
public TimeZoneTransition getPreviousTransition(long base, boolean inclusive)

Implements abstract com.ibm.icu.util.BasicTimeZone.getPreviousTransition.

Doc from com.ibm.icu.util.BasicTimeZone.getPreviousTransition.

ICU

Returns the last time zone transition before the base time.

Example code:{@. jcite com.ibm.icu.samples.util.timezone.BasicTimeZoneExample:---getPreviousTransitionExample}

Parameters
base:long

The base time.

inclusive:boolean

Whether the base time is inclusive or not.

Returns:TimeZoneTransition

A Date holding the last time zone transition time before the given base time, or null if no time zone transitions are available before the base time.

Annotations
@Override
getRawOffsetback to summary
public int getRawOffset()

Implements abstract com.ibm.icu.util.TimeZone.getRawOffset.

Doc from com.ibm.icu.util.TimeZone.getRawOffset.

Gets unmodified offset, NOT modified in case of daylight savings. This is the offset to add to UTC to get local time.

Returns:int

the unmodified offset to add to UTC to get local time.

Annotations
@Override
getTimeZoneRulesback to summary
public TimeZoneRule[] getTimeZoneRules()

Implements abstract com.ibm.icu.util.BasicTimeZone.getTimeZoneRules.

Doc from com.ibm.icu.util.BasicTimeZone.getTimeZoneRules.

ICU

Returns the array of TimeZoneRule which represents the rule of this time zone object. The first element in the result array will be the InitialTimeZoneRule instance for the initial rule. The rest will be either AnnualTimeZoneRule or TimeArrayTimeZoneRule instances representing transitions.
Returns:TimeZoneRule[]

The array of TimeZoneRule which represents this time zone.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides com.ibm.icu.util.TimeZone.hashCode.

Doc from com.ibm.icu.util.TimeZone.hashCode.

Overrides hashCode.

Returns:int

a hash code value for this object.

Annotations
@Override
hasSameRulesback to summary
public boolean hasSameRules(TimeZone other)

Overrides com.ibm.icu.util.TimeZone.hasSameRules.

Doc from com.ibm.icu.util.TimeZone.hasSameRules.

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.

Parameters
other:TimeZone

the TimeZone object to be compared with

Returns:boolean

true if the other zone is not null and is the same as this one, with the possible exception of the ID

Annotations
@Override
inDaylightTimeback to summary
public boolean inDaylightTime(Date date)

Implements abstract com.ibm.icu.util.TimeZone.inDaylightTime.

Doc from com.ibm.icu.util.TimeZone.inDaylightTime.

Queries if the given date is in daylight savings time in this time zone.

Parameters
date:Date

the given Date.

Returns:boolean

true if the given date is in daylight savings time, false, otherwise.

Annotations
@Override
initialDstOffsetback to summary
private int initialDstOffset()
initialRawOffsetback to summary
private int initialRawOffset()
initTransitionRulesback to summary
private synchronized void initTransitionRules()
isFrozenback to summary
public boolean isFrozen()

Overrides com.ibm.icu.util.TimeZone.isFrozen.

Implements com.ibm.icu.util.Freezable.isFrozen.

Doc from com.ibm.icu.util.TimeZone.isFrozen.

Determines whether the object has been frozen or not.

Annotations
@Override
loadRuleback to summary
private static UResourceBundle loadRule(UResourceBundle top, String ruleid)
observesDaylightTimeback to summary
public boolean observesDaylightTime()

Overrides com.ibm.icu.util.TimeZone.observesDaylightTime.

Doc from com.ibm.icu.util.TimeZone.observesDaylightTime.

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 if useDaylightTime() or inDaylightTime(new Date()) returns true.

Note

This method was added for java.util.TimeZone compatibility support. The java.util.TimeZone#useDaylightTime() method only checks the last known rule(s), therefore it may return false even the zone observes daylight saving time currently. java.util.TimeZone added observesDaylightTime() to resolve the issue. In ICU, useDaylightTime() works differently. The ICU implementation checks if the zone uses daylight saving time in the current calendar year. Therefore, it will never return false if daylight saving time is currently used.

ICU's TimeZone subclass implementations override this method to support the same behavior with java.util.TimeZone#observesDaylightTime(). Unlike useDaylightTime(), the implementation does not take past daylight saving time into account, so that this method may return false even when useDaylightTime() returns true.

Returns:boolean

true if this time zone is in daylight saving time or will observe daylight saving time at any future time.

Annotations
@Override
rawOffsetAtback to summary
private int rawOffsetAt(int transIdx)
readObjectback to summary
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException
setIDback to summary
public void setID(String id)

Overrides com.ibm.icu.util.TimeZone.setID.

Doc from com.ibm.icu.util.TimeZone.setID.

Sets the time zone ID. This does not change any other data in the time zone object.

Parameters
id:String

the new time zone ID.

Annotations
@Override
setRawOffsetback to summary
public void setRawOffset(int offsetMillis)

Implements abstract com.ibm.icu.util.TimeZone.setRawOffset.

Doc from com.ibm.icu.util.TimeZone.setRawOffset.

Sets the base time zone offset to GMT. This is the offset to add to UTC to get local time.

Parameters
offsetMillis:int

the given base time zone offset to GMT.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
useDaylightTimeback to summary
public boolean useDaylightTime()

Implements abstract com.ibm.icu.util.TimeZone.useDaylightTime.

Doc from com.ibm.icu.util.TimeZone.useDaylightTime.

Queries if this time zone uses daylight savings time.

Returns:boolean

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 returns true when the time zone uses daylight savings time in the current (Gregorian) calendar year.

Annotations
@Override
zoneOffsetAtback to summary
private int zoneOffsetAt(int transIdx)