Class RuleBasedTimeZone
- All Implemented Interfaces:
Serializable,Cloneable,Freezable<TimeZone>
RuleBasedTimeZone is a concrete subclass of TimeZone that allows users to define
custom historic time transition rules.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.graalvm.shadowed.com.ibm.icu.util.BasicTimeZone
BasicTimeZone.LocalOptionNested classes/interfaces inherited from class org.graalvm.shadowed.com.ibm.icu.util.TimeZone
TimeZone.SystemTimeZoneType -
Field Summary
Fields inherited from class org.graalvm.shadowed.com.ibm.icu.util.BasicTimeZone
FORMER_LATTER_MASK, LOCAL_DST, LOCAL_FORMER, LOCAL_LATTER, LOCAL_STD, STD_DST_MASKFields inherited from class org.graalvm.shadowed.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
ConstructorsConstructorDescriptionRuleBasedTimeZone(String id, InitialTimeZoneRule initialRule) Constructs aRuleBasedTimeZoneobject with the ID and theInitialTimeZoneRule -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds theTimeZoneRulewhich represents time transitions.clone()Overrides clone.Provides for the clone operation.freeze()Freezes the object.getNextTransition(long base, boolean inclusive) Returns the first time zone transition after the base time.intgetOffset(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.voidgetOffset(long time, boolean local, int[] offsets) Returns the time zone raw and GMT offset for the given moment in time.voidgetOffsetFromLocal(long date, BasicTimeZone.LocalOption nonExistingTimeOpt, BasicTimeZone.LocalOption duplicatedTimeOpt, int[] offsets) Returns time zone offsets from local wall time.getPreviousTransition(long base, boolean inclusive) Returns the last time zone transition before the base time.intGets unmodified offset, NOT modified in case of daylight savings.Returns the array ofTimeZoneRulewhich represents the rule of this time zone object.booleanhasSameRules(TimeZone other) Returns true if this zone has the same rule and offset as another zone.booleaninDaylightTime(Date date) Queries if the given date is in daylight savings time in this time zone.booleanisFrozen()Determines whether the object has been frozen or not.booleanQueries if this time zone is in daylight saving time or will observe daylight saving time at any future time.voidsetRawOffset(int offsetMillis) Sets the base time zone offset to GMT.booleanQueries if this time zone uses daylight savings time.Methods inherited from class org.graalvm.shadowed.com.ibm.icu.util.BasicTimeZone
getLocalOptionValue, getSimpleTimeZoneRulesNear, getTimeZoneRules, hasEquivalentTransitions, hasEquivalentTransitionsMethods inherited from class org.graalvm.shadowed.com.ibm.icu.util.TimeZone
countEquivalentIDs, equals, forLocaleOrDefault, forULocaleOrDefault, getAvailableIDs, getAvailableIDs, getAvailableIDs, getAvailableIDs, getCanonicalID, getCanonicalID, getDefault, getDefaultTimeZoneType, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getDSTSavings, getEquivalentID, getFrozenTimeZone, getIanaID, getID, getIDForWindowsID, getOffset, getRegion, getTimeZone, getTimeZone, getTZDataVersion, getWindowsID, hashCode, setDefault, setDefaultTimeZoneType, setICUDefault, setID
-
Constructor Details
-
RuleBasedTimeZone
Constructs aRuleBasedTimeZoneobject with the ID and theInitialTimeZoneRule- Parameters:
id- The time zone ID.initialRule- The initial time zone rule.
-
-
Method Details
-
addTransitionRule
Adds theTimeZoneRulewhich represents time transitions. TheTimeZoneRulemust have start times, that is, the result ofTimeZoneRule.isTransitionRule()must be true. Otherwise,IllegalArgumentExceptionis thrown.- Parameters:
rule- TheTimeZoneRule.
-
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:
getOffsetin 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 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:
getOffsetin classTimeZone- 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 onlocal.local- if true,dateis 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 torawOffsetto 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.
-
getOffsetFromLocal
public void getOffsetFromLocal(long date, BasicTimeZone.LocalOption nonExistingTimeOpt, BasicTimeZone.LocalOption duplicatedTimeOpt, int[] offsets) Returns time zone offsets from local wall time.- Overrides:
getOffsetFromLocalin classBasicTimeZone
-
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:
getRawOffsetin classTimeZone- Returns:
- the unmodified offset to add to UTC to get local time.
-
inDaylightTime
Queries if the given date is in daylight savings time in this time zone.- Specified by:
inDaylightTimein classTimeZone- Parameters:
date- the given Date.- Returns:
- true if the given date is in daylight savings time, false, otherwise.
-
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:
setRawOffsetin classTimeZone- Parameters:
offsetMillis- the given base time zone offset to GMT.
-
useDaylightTime
public boolean useDaylightTime()Queries if this time zone uses daylight savings time.- Specified by:
useDaylightTimein 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
falsefor such case. The default implementation of this method returnstruewhen the time zone uses daylight savings time in the current (Gregorian) calendar year.
-
observesDaylightTime
public boolean 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
trueifTimeZone.useDaylightTime()orinDaylightTime(new Date())returnstrue.Note: This method was added for
TimeZonecompatibility support. TheTimeZone.useDaylightTime()method only checks the last known rule(s), therefore it may return false even the zone observes daylight saving time currently.TimeZoneaddedobservesDaylightTime()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 returnfalseif 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 returnfalseeven whenTimeZone.useDaylightTime()returnstrue.- Overrides:
observesDaylightTimein classTimeZone- Returns:
trueif this time zone is in daylight saving time or will observe daylight saving time at any future time.- See Also:
-
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.- Overrides:
hasSameRulesin classTimeZone- Parameters:
other- theTimeZoneobject 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
-
getTimeZoneRules
Returns the array ofTimeZoneRulewhich represents the rule of this time zone object. The first element in the result array will be theInitialTimeZoneRuleinstance for the initial rule. The rest will be eitherAnnualTimeZoneRuleorTimeArrayTimeZoneRuleinstances representing transitions.- Specified by:
getTimeZoneRulesin classBasicTimeZone- Returns:
- The array of
TimeZoneRulewhich represents this time zone.
-
getNextTransition
Returns the first time zone transition after the base time.Example code:invalid input: '{@'.jcite org.graalvm.shadowed.com.ibm.icu.samples.util.timezone.BasicTimeZoneExample:---getNextTransitionExample}
- Specified by:
getNextTransitionin classBasicTimeZone- Parameters:
base- The base time.inclusive- Whether the base time is inclusive or not.- Returns:
- A
Dateholding the first time zone transition time after the given base time, or null if no time zone transitions are available after the base time.
-
getPreviousTransition
Returns the last time zone transition before the base time.Example code:invalid input: '{@'.jcite org.graalvm.shadowed.com.ibm.icu.samples.util.timezone.BasicTimeZoneExample:---getPreviousTransitionExample}
- Specified by:
getPreviousTransitionin classBasicTimeZone- Parameters:
base- The base time.inclusive- Whether the base time is inclusive or not.- Returns:
- A
Dateholding the last time zone transition time before the given base time, or null if no time zone transitions are available before the base time.
-
clone
-
isFrozen
-
freeze
-
cloneAsThawed
Provides for the clone operation. Any clone is initially unfrozen.- Specified by:
cloneAsThawedin interfaceFreezable<TimeZone>- Overrides:
cloneAsThawedin classTimeZone
-