Class OlsonTimeZone
- All Implemented Interfaces:
Freezable<TimeZone>, Serializable, Cloneable
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class BasicTimeZone
BasicTimeZone.LocalOptionNested classes/interfaces inherited from class TimeZone
TimeZone.SystemTimeZoneType -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate StringThe canonical ID of this zone.private static final intprivate static final booleanprivate doubleFor date >= finalStartMillis, the finalZone will be used.private intFor year >= finalStartYear, the finalZone will be used.private SimpleTimeZoneA SimpleTimeZone that governs the behavior for years >= finalYear.private SimpleTimeZoneprivate TimeZoneTransitionprivate TimeZoneTransitionprivate intprivate TimeArrayTimeZoneRule[]private InitialTimeZoneRuleprivate booleanprivate static final intprivate static final intprivate int(package private) static final longprivate intNumber of transitions, 0..~370private booleanprivate long[]Time of each transition in seconds from 1970 epoch.private intNumber of types, 1..255private byte[]Type description data, consisting of transitionCount uint8_t type indices (from 0..typeCount-1).private int[]Offset from GMT in seconds for each type.private static final StringFields inherited from class BasicTimeZone
FORMER_LATTER_MASK, LOCAL_DST, LOCAL_FORMER, LOCAL_LATTER, LOCAL_STD, STD_DST_MASKFields inherited from class 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
ConstructorsConstructorDescriptionOlsonTimeZone(UResourceBundle top, UResourceBundle res, String id) Construct from a resource bundleOlsonTimeZone(String id) -
Method Summary
Modifier and TypeMethodDescriptionclone()Overrides clone.Provides for the clone operation.private voidconstruct(UResourceBundle top, UResourceBundle res, String id) private voidConstruct a GMT+0 zone with no transitions.private intdstOffsetAt(int transIdx) booleanOverrides equals.freeze()Freezes the object.Returns the canonical ID of this system time zoneintTimeZone API Returns the amount of time to be added to local standard time to get local wall clock time.private voidgetHistoricalOffset(long date, boolean local, int NonExistingTimeOpt, int DuplicatedTimeOpt, int[] offsets) private intgetInt(byte val) 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.intgetOffset(int era, int year, int month, int dom, int dow, int millis, int monthLength) TimeZone API.voidgetOffset(long date, boolean local, int[] offsets) TimeZone API.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.inthashCode()Overrides hashCode.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.private intprivate intprivate voidbooleanisFrozen()Determines whether the object has been frozen or not.private static UResourceBundleloadRule(UResourceBundle top, String ruleid) booleanQueries if this time zone is in daylight saving time or will observe daylight saving time at any future time.private intrawOffsetAt(int transIdx) private voidreadObject(ObjectInputStream stream) voidSets the time zone ID.voidsetRawOffset(int offsetMillis) Sets the base time zone offset to GMT.toString()booleanQueries if this time zone uses daylight savings time.private intzoneOffsetAt(int transIdx) Methods inherited from class BasicTimeZone
getLocalOptionValue, getSimpleTimeZoneRulesNear, getTimeZoneRules, hasEquivalentTransitions, hasEquivalentTransitionsMethods inherited from class TimeZone
countEquivalentIDs, forLocaleOrDefault, forULocaleOrDefault, getAvailableIDs, getAvailableIDs, getAvailableIDs, getAvailableIDs, getCanonicalID, getCanonicalID, getDefault, getDefaultTimeZoneType, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getEquivalentID, getFrozenTimeZone, getIanaID, getID, getIDForWindowsID, getOffset, getRegion, getTimeZone, getTimeZone, getTZDataVersion, getWindowsID, setDefault, setDefaultTimeZoneType, setICUDefault
-
Field Details
-
serialVersionUID
static final long serialVersionUID- See Also:
-
MAX_OFFSET_SECONDS
private static final int MAX_OFFSET_SECONDS- See Also:
-
transitionCount
private int transitionCountNumber of transitions, 0..~370 -
typeCount
private int typeCountNumber of types, 1..255 -
transitionTimes64
private long[] transitionTimes64Time of each transition in seconds from 1970 epoch. -
typeOffsets
private int[] typeOffsetsOffset from GMT in seconds for each type. Length is equal to typeCount -
typeMapData
private byte[] typeMapDataType description data, consisting of transitionCount uint8_t type indices (from 0..typeCount-1). Length is equal to transitionCount -
finalStartYear
private int finalStartYearFor year >= finalStartYear, the finalZone will be used. -
finalStartMillis
private double finalStartMillisFor date >= finalStartMillis, the finalZone will be used. -
finalZone
A SimpleTimeZone that governs the behavior for years >= finalYear. If and only if finalYear == INT32_MAX then finalZone == 0. -
canonicalID
The canonical ID of this zone. Initialized whengetCanonicalID()is invoked first time, orsetID(String)is called. -
ZONEINFORES
- See Also:
-
DEBUG
private static final boolean DEBUG -
SECONDS_PER_DAY
private static final int SECONDS_PER_DAY- See Also:
-
initialRule
-
firstTZTransition
-
firstTZTransitionIdx
private transient int firstTZTransitionIdx -
firstFinalTZTransition
-
historicRules
-
finalZoneWithStartYear
-
transitionRulesInitialized
private transient boolean transitionRulesInitialized -
currentSerialVersion
private static final int currentSerialVersion- See Also:
-
serialVersionOnStream
private int serialVersionOnStream -
isFrozen
private transient volatile boolean isFrozen
-
-
Constructor Details
-
OlsonTimeZone
Construct from a resource bundle- Parameters:
top- the top-level zoneinfo resource bundle. This is used to lookup the rule thatresmay refer to, if there is one.res- the resource bundle of the zone to be constructedid- time zone ID
-
OlsonTimeZone
-
-
Method Details
-
getOffset
public int getOffset(int era, int year, int month, int day, int dayOfWeek, int milliseconds) Description copied from class:TimeZoneGets 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 int getOffset(int era, int year, int month, int dom, int dow, int millis, int monthLength) TimeZone API. -
setRawOffset
public void setRawOffset(int offsetMillis) Description copied from class:TimeZoneSets 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.
-
clone
Description copied from class:TimeZoneOverrides clone. -
getOffset
public void getOffset(long date, boolean local, int[] offsets) TimeZone API.- Overrides:
getOffsetin 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,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()Description copied from class:TimeZoneGets 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.
-
useDaylightTime
public boolean useDaylightTime()Description copied from class:TimeZoneQueries 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()Description copied from class:TimeZoneQueries 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:
-
getDSTSavings
public int getDSTSavings()TimeZone API Returns the amount of time to be added to local standard time to get local wall clock time.- Overrides:
getDSTSavingsin classTimeZone- Returns:
- the amount of saving time in milliseconds
-
inDaylightTime
Description copied from class:TimeZoneQueries 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.
-
hasSameRules
Description copied from class:TimeZoneReturns 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
-
getCanonicalID
Returns the canonical ID of this system time zone -
constructEmpty
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. -
construct
-
setID
-
getHistoricalOffset
private void getHistoricalOffset(long date, boolean local, int NonExistingTimeOpt, int DuplicatedTimeOpt, int[] offsets) -
getInt
private int getInt(byte val) -
zoneOffsetAt
private int zoneOffsetAt(int transIdx) -
rawOffsetAt
private int rawOffsetAt(int transIdx) -
dstOffsetAt
private int dstOffsetAt(int transIdx) -
initialRawOffset
private int initialRawOffset() -
initialDstOffset
private int initialDstOffset() -
toString
-
loadRule
-
equals
-
hashCode
-
getNextTransition
Description copied from class:BasicTimeZoneReturns the first time zone transition after the base time.Example code:
System.out.println("### Iterates time zone transitions in America/Los_Angeles starting 2005-01-01 and forward"); // A TimeZone instance created by getTimeZone with TIMEZONE_ICU is always a BasicTimeZone BasicTimeZone btz = (BasicTimeZone)TimeZone.getTimeZone("America/Los_Angeles", TimeZone.TIMEZONE_ICU); // Date format for the wall time SimpleDateFormat wallTimeFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z", ULocale.US); wallTimeFmt.setTimeZone(btz); long start = 1104537600000L; // 2005-01-01 0:00 UTC for (int i = 0; i < 5; i++) { // Up to 5 transitions TimeZoneTransition trans = btz.getNextTransition(start, false /* not including start time */); // Display the transition time and offset information long transTime = trans.getTime(); System.out.println(wallTimeFmt.format(new Date(transTime - 1)) + " -> " + wallTimeFmt.format(new Date(transTime))); System.out.println(" - Before (Offset/Save): " + trans.getFrom().getRawOffset() + "/" + trans.getFrom().getDSTSavings()); System.out.println(" - After (Offset/Save): " + trans.getTo().getRawOffset() + "/" + trans.getTo().getDSTSavings()); // Update start time for next transition start = transTime; }- 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
Description copied from class:BasicTimeZoneReturns the last time zone transition before the base time.Example code:
System.out.println("### Iterates time zone transitions in America/Los_Angeles starting 2010-01-01 and backward"); // A TimeZone instance created by getTimeZone with TIMEZONE_ICU is always a BasicTimeZone BasicTimeZone btz = (BasicTimeZone)TimeZone.getTimeZone("America/Los_Angeles", TimeZone.TIMEZONE_ICU); // Date format for the wall time SimpleDateFormat wallTimeFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z", ULocale.US); wallTimeFmt.setTimeZone(btz); long start = 1262304000000L; // 2010-01-01 0:00 UTC for (int i = 0; i < 5; i++) { // Up to 5 transitions TimeZoneTransition trans = btz.getPreviousTransition(start, false /* not including start time */); // Display the transition time and offset information long transTime = trans.getTime(); System.out.println(wallTimeFmt.format(new Date(transTime - 1)) + " -> " + wallTimeFmt.format(new Date(transTime))); System.out.println(" - Before (Offset/Save): " + trans.getFrom().getRawOffset() + "/" + trans.getFrom().getDSTSavings()); System.out.println(" - After (Offset/Save): " + trans.getTo().getRawOffset() + "/" + trans.getTo().getDSTSavings()); // Update start time for next transition start = transTime; }- 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.
-
getTimeZoneRules
Description copied from class:BasicTimeZoneReturns 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.
-
initTransitionRules
private void initTransitionRules() -
readObject
- Throws:
IOExceptionClassNotFoundException
-
isFrozen
-
freeze
-
cloneAsThawed
Description copied from class:TimeZoneProvides for the clone operation. Any clone is initially unfrozen.- Specified by:
cloneAsThawedin interfaceFreezable<TimeZone>- Overrides:
cloneAsThawedin classTimeZone
-