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

public Class RuleBasedTimeZone

extends BasicTimeZone
Class Inheritance
Imports
java.util.ArrayList, .BitSet, .Date, .List, com.ibm.icu.impl.Grego

RuleBasedTimeZone is a concrete subclass of TimeZone that allows users to define custom historic time transition rules.
ICU Status
Stable since ICU 3.8.
See Also
com.ibm.icu.util.TimeZoneRule

Field Summary

Modifier and TypeField and Description
private AnnualTimeZoneRule[]
private List<TimeZoneRule>
private transient List<TimeZoneTransition>
private final InitialTimeZoneRule
private transient volatile boolean
private static final long
private transient boolean
Inherited from com.ibm.icu.util.BasicTimeZone:
FORMER_LATTER_MASKLOCAL_DSTLOCAL_FORMERLOCAL_LATTERLOCAL_STDSTD_DST_MASK

Constructor Summary

AccessConstructor and Description
public
RuleBasedTimeZone(String
The time zone ID.
id
,
InitialTimeZoneRule
The initial time zone rule.
initialRule
)

Constructs a RuleBasedTimeZone object with the ID and the InitialTimeZoneRule

Method Summary

Modifier and TypeMethod and Description
public void
addTransitionRule(TimeZoneRule
The TimeZoneRule.
rule
)

Adds the TimeZoneRule which represents time transitions.

public Object
clone()

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

Overrides clone.
public TimeZone
private void
private TimeZoneRule
findRuleInFinal(long time, boolean local, int NonExistingTimeOpt, int DuplicatedTimeOpt)

public TimeZone
private static int
getLocalDelta(int rawBefore, int dstBefore, int rawAfter, int dstAfter, int NonExistingTimeOpt, int DuplicatedTimeOpt)

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 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.
time
,
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.

Returns the time zone raw and GMT offset for the given moment in time.
private void
getOffset(long time, boolean local, int NonExistingTimeOpt, int DuplicatedTimeOpt, int[] offsets)

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[]
private static long
getTransitionTime(TimeZoneTransition tzt, boolean local, int NonExistingTimeOpt, int DuplicatedTimeOpt)

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.
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.
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.
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 boolean
useDaylightTime()

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

Queries if this time zone uses daylight savings time.
Inherited from com.ibm.icu.util.BasicTimeZone:
getLocalOptionValuegetSimpleTimeZoneRulesNeargetTimeZoneRuleshasEquivalentTransitionshasEquivalentTransitions

Field Detail

finalRulesback to summary
private AnnualTimeZoneRule[] finalRules
historicRulesback to summary
private List<TimeZoneRule> historicRules
historicTransitionsback to summary
private transient List<TimeZoneTransition> historicTransitions
initialRuleback to summary
private final InitialTimeZoneRule initialRule
isFrozenback to summary
private transient volatile boolean isFrozen
serialVersionUIDback to summary
private static final long serialVersionUID

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

upToDateback to summary
private transient boolean upToDate

Constructor Detail

RuleBasedTimeZoneback to summary
public RuleBasedTimeZone(String id, InitialTimeZoneRule initialRule)

Constructs a RuleBasedTimeZone object with the ID and the InitialTimeZoneRule

Parameters
id:String

The time zone ID.

initialRule:InitialTimeZoneRule

The initial time zone rule.

ICU Status
Stable since ICU 3.8.

Method Detail

addTransitionRuleback to summary
public void addTransitionRule(TimeZoneRule rule)

Adds the TimeZoneRule which represents time transitions. The TimeZoneRule must have start times, that is, the result of com.ibm.icu.util.TimeZoneRule#isTransitionRule() must be true. Otherwise, IllegalArgumentException is thrown.

Parameters
rule:TimeZoneRule

The TimeZoneRule.

ICU Status
Stable since ICU 3.8.
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
ICU Status
Stable since ICU 3.8.
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
ICU Status
Stable since ICU 49.
completeback to summary
private void complete()
findRuleInFinalback to summary
private TimeZoneRule findRuleInFinal(long time, boolean local, int NonExistingTimeOpt, int DuplicatedTimeOpt)
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
ICU Status
Stable since ICU 49.
getLocalDeltaback to summary
private static int getLocalDelta(int rawBefore, int dstBefore, int rawAfter, int dstAfter, int NonExistingTimeOpt, int DuplicatedTimeOpt)
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
ICU Status
Stable since ICU 3.8.
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
ICU Status
Stable since ICU 3.8.
getOffsetback to summary
public void getOffset(long time, boolean local, int[] offsets)

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

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

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().

Parameters
time: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.

local:boolean

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

offsets: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.

Annotations
@Override
ICU Status
Stable since ICU 3.8.
getOffsetback to summary
private void getOffset(long time, boolean local, int NonExistingTimeOpt, int DuplicatedTimeOpt, int[] offsets)
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
ICU Status
Stable since ICU 69.
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
ICU Status
Stable since ICU 3.8.
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
ICU Status
Stable since ICU 3.8.
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
ICU Status
Stable since ICU 3.8.
getTransitionTimeback to summary
private static long getTransitionTime(TimeZoneTransition tzt, boolean local, int NonExistingTimeOpt, int DuplicatedTimeOpt)
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
ICU Status
Stable since ICU 3.8.
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
ICU Status
Stable since ICU 3.8.
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
ICU Status
Stable since ICU 49.
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
ICU Status
Stable since ICU 49.
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
ICU Status
Stable since ICU 3.8.
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
ICU Status
Stable since ICU 3.8.