com.ibm.icu.util
Class RuleBasedTimeZone

java.lang.Object
  extended by com.ibm.icu.util.TimeZone
      extended by com.ibm.icu.util.BasicTimeZone
          extended by com.ibm.icu.util.RuleBasedTimeZone
All Implemented Interfaces:
Serializable, Cloneable

public class RuleBasedTimeZone
extends BasicTimeZone

RuleBasedTimeZone is a concrete subclass of TimeZone that allows users to define custom historic time transition rules.

See Also:
TimeZoneRule, Serialized Form
Status:
Stable ICU 3.8.

Field Summary
 
Fields inherited from class com.ibm.icu.util.BasicTimeZone
FORMER_LATTER_MASK, LOCAL_DST, LOCAL_FORMER, LOCAL_LATTER, LOCAL_STD, STD_DST_MASK
 
Fields inherited from class com.ibm.icu.util.TimeZone
LONG, SHORT, TIMEZONE_ICU, TIMEZONE_JDK
 
Constructor Summary
RuleBasedTimeZone(String id, InitialTimeZoneRule initialRule)
          Constructs a RuleBasedTimeZone object with the ID and the InitialTimeZoneRule
 
Method Summary
 void addTransitionRule(TimeZoneRule rule)
          Adds the TimeZoneRule which represents time transitions.
 Object clone()
          Overrides Cloneable
 TimeZoneTransition getNextTransition(long base, boolean inclusive)
          Gets the first time zone transition after the base time.
 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.
 void getOffset(long time, boolean local, int[] offsets)
          Returns the time zone raw and GMT offset for the given moment in time.
 void getOffsetFromLocal(long date, int nonExistingTimeOpt, int duplicatedTimeOpt, int[] offsets)
          Deprecated. This API is ICU internal only.
 TimeZoneTransition getPreviousTransition(long base, boolean inclusive)
          Gets the last time zone transition before the base time.
 int getRawOffset()
          Gets unmodified offset, NOT modified in case of daylight savings.
 TimeZoneRule[] getTimeZoneRules()
          Gets the array of TimeZoneRule which represents the rule of this time zone object.
 boolean hasSameRules(TimeZone other)
          Returns true if this zone has the same rule and offset as another zone.
 boolean inDaylightTime(Date date)
          Queries if the given date is in daylight savings time in this time zone.
 void setRawOffset(int offsetMillis)
          Sets the base time zone offset to GMT.
 boolean useDaylightTime()
          Queries if this time zone uses daylight savings time.
 
Methods inherited from class com.ibm.icu.util.BasicTimeZone
getSimpleTimeZoneRulesNear, getTimeZoneRules, hasEquivalentTransitions, hasEquivalentTransitions
 
Methods inherited from class com.ibm.icu.util.TimeZone
countEquivalentIDs, equals, getAvailableIDs, getAvailableIDs, getAvailableIDs, getCanonicalID, getCanonicalID, getDefault, getDefaultTimeZoneType, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getDSTSavings, getEquivalentID, getID, getOffset, getTimeZone, getTimeZone, getTZDataVersion, hashCode, setDefault, setDefaultTimeZoneType, setID
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RuleBasedTimeZone

public RuleBasedTimeZone(String id,
                         InitialTimeZoneRule initialRule)
Constructs a RuleBasedTimeZone object with the ID and the InitialTimeZoneRule

Parameters:
id - The time zone ID.
initialRule - The initial time zone rule.
Status:
Stable ICU 3.8.
Method Detail

addTransitionRule

public void addTransitionRule(TimeZoneRule rule)
Adds the TimeZoneRule which represents time transitions. The TimeZoneRule must have start times, that is, the result of TimeZoneRule.isTransitionRule() must be true. Otherwise, IllegalArgumentException is thrown.

Parameters:
rule - The TimeZoneRule.
Status:
Stable ICU 3.8.

getOffset

public 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. This is the offset to add *to* UTC to get local time.

Specified by:
getOffset in class TimeZone
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.
Status:
Stable ICU 3.8.

getOffset

public void getOffset(long time,
                      boolean local,
                      int[] offsets)
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 class TimeZone
Parameters:
time - 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 - 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 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.
Status:
Stable ICU 3.8.

getOffsetFromLocal

public void getOffsetFromLocal(long date,
                               int nonExistingTimeOpt,
                               int duplicatedTimeOpt,
                               int[] offsets)
Deprecated. This API is ICU internal only.

Get time zone offsets from local wall time.

Overrides:
getOffsetFromLocal in class BasicTimeZone
Status:
Internal. This API is ICU internal only.

getRawOffset

public int getRawOffset()
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 class TimeZone
Returns:
the unmodified offset to add *to* UTC to get local time.
Status:
Stable ICU 3.8.

inDaylightTime

public boolean inDaylightTime(Date date)
Queries if the given date is in daylight savings time in this time zone.

Specified by:
inDaylightTime in class TimeZone
Parameters:
date - the given Date.
Returns:
true if the given date is in daylight savings time, false, otherwise.
Status:
Stable ICU 3.8.

setRawOffset

public void setRawOffset(int offsetMillis)
Sets the base time zone offset to GMT. This is the offset to add *to* UTC to get local time.

Specified by:
setRawOffset in class TimeZone
Parameters:
offsetMillis - the given base time zone offset to GMT.
Status:
Stable ICU 3.8.

useDaylightTime

public boolean useDaylightTime()
Queries if this time zone uses daylight savings time.

Specified by:
useDaylightTime in class TimeZone
Returns:
true if this time zone uses daylight savings time, false, otherwise.
Status:
Stable ICU 3.8.

hasSameRules

public boolean hasSameRules(TimeZone other)
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 class TimeZone
Parameters:
other - the TimeZone 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
Status:
Stable ICU 3.8.

getTimeZoneRules

public TimeZoneRule[] getTimeZoneRules()
Gets 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.

Specified by:
getTimeZoneRules in class BasicTimeZone
Returns:
The array of TimeZoneRule which represents this time zone.
Status:
Stable ICU 3.8.

getNextTransition

public TimeZoneTransition getNextTransition(long base,
                                            boolean inclusive)
Gets the first time zone transition after the base time.

Specified by:
getNextTransition in class BasicTimeZone
Parameters:
base - The base time.
inclusive - Whether the base time is inclusive or not.
Returns:
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.
Status:
Stable ICU 3.8.

getPreviousTransition

public TimeZoneTransition getPreviousTransition(long base,
                                                boolean inclusive)
Gets the last time zone transition before the base time.

Specified by:
getPreviousTransition in class BasicTimeZone
Parameters:
base - The base time.
inclusive - Whether the base time is inclusive or not.
Returns:
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.
Status:
Stable ICU 3.8.

clone

public Object clone()
Overrides Cloneable

Overrides:
clone in class TimeZone
Status:
Stable ICU 3.8.


Copyright (c) 2009 IBM Corporation and others.