Class SimpleTimeZone
- java.lang.Object
-
- com.ibm.icu.util.TimeZone
-
- com.ibm.icu.util.BasicTimeZone
-
- com.ibm.icu.util.SimpleTimeZone
-
public class SimpleTimeZone extends BasicTimeZone
.SimpleTimeZone
is a concrete subclass ofTimeZone
that represents a time zone for use with a Gregorian calendar. This class does not handle historical changes.Use a negative value for
dayOfWeekInMonth
to indicate thatSimpleTimeZone
should count from the end of the month backwards. For example, if Daylight Savings Time starts or ends at the last Sunday in a month, usedayOfWeekInMonth = -1
along withdayOfWeek = Calendar.SUNDAY
to specify the rule.- See Also:
Calendar
,GregorianCalendar
,TimeZone
, Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.ibm.icu.util.BasicTimeZone
BasicTimeZone.LocalOption
-
Nested classes/interfaces inherited from class com.ibm.icu.util.TimeZone
TimeZone.SystemTimeZoneType
-
-
Field Summary
Fields Modifier and Type Field Description private static int
DOM_MODE
private static int
DOW_GE_DOM_MODE
private static int
DOW_IN_MONTH_MODE
private static int
DOW_LE_DOM_MODE
private int
dst
private AnnualTimeZoneRule
dstRule
private int
endDay
private int
endDayOfWeek
private int
endMode
private int
endMonth
private int
endTime
private int
endTimeMode
private TimeZoneTransition
firstTransition
private InitialTimeZoneRule
initialRule
private boolean
isFrozen
private int
raw
private static long
serialVersionUID
static int
STANDARD_TIME
Constant for a mode of start or end time specified as local standard time.private int
startDay
private int
startDayOfWeek
private int
startMode
private int
startMonth
private int
startTime
private int
startTimeMode
private int
startYear
private static byte[]
staticMonthLength
private AnnualTimeZoneRule
stdRule
private boolean
transitionRulesInitialized
private boolean
useDaylight
static int
UTC_TIME
Constant for a mode of start or end time specified as UTC.static int
WALL_TIME
Constant for a mode of start or end time specified as local wall time.private STZInfo
xinfo
-
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
GENERIC_LOCATION, GMT_ZONE, GMT_ZONE_ID, LONG, LONG_GENERIC, LONG_GMT, SHORT, SHORT_COMMONLY_USED, SHORT_GENERIC, SHORT_GMT, TIMEZONE_ICU, TIMEZONE_JDK, UNKNOWN_ZONE, UNKNOWN_ZONE_ID
-
-
Constructor Summary
Constructors Constructor Description SimpleTimeZone(int rawOffset, java.lang.String ID)
Constructs a SimpleTimeZone with the given base time zone offset from GMT and time zone ID.SimpleTimeZone(int rawOffset, java.lang.String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int endMonth, int endDay, int endDayOfWeek, int endTime)
Constructs a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, time to start and end the daylight time.SimpleTimeZone(int rawOffset, java.lang.String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int endMonth, int endDay, int endDayOfWeek, int endTime, int dstSavings)
Constructor.SimpleTimeZone(int rawOffset, java.lang.String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int startTimeMode, int endMonth, int endDay, int endDayOfWeek, int endTime, int endTimeMode, int dstSavings)
Constructs a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, time and its mode to start and end the daylight time.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.lang.Object
clone()
Overrides clone.TimeZone
cloneAsThawed()
Provides for the clone operation.private int
compareToRule(int month, int monthLen, int prevMonthLen, int dayOfMonth, int dayOfWeek, int millis, int millisDelta, int ruleMode, int ruleMonth, int ruleDayOfWeek, int ruleDay, int ruleMillis)
Compare a given date in the year to a rule.private void
construct(int _raw, int _startMonth, int _startDay, int _startDayOfWeek, int _startTime, int _startTimeMode, int _endMonth, int _endDay, int _endDayOfWeek, int _endTime, int _endTimeMode, int _dst)
Internal construction method.private void
decodeEndRule()
Decode the end rule and validate the parameters.private void
decodeRules()
private void
decodeStartRule()
Decode the start rule and validate the parameters.boolean
equals(java.lang.Object obj)
Overrides equals.TimeZone
freeze()
Freezes the object.int
getDSTSavings()
Returns the amount of time in ms that the clock is advanced during DST.TimeZoneTransition
getNextTransition(long base, boolean inclusive)
Returns the first time zone transition after the base time.int
getOffset(int era, int year, int month, int day, int dayOfWeek, int millis)
Gets the time zone offset, for current date, modified in case of daylight savings.int
getOffset(int era, int year, int month, int day, int dayOfWeek, int millis, int monthLength)
Deprecated.This API is ICU internal only.private int
getOffset(int era, int year, int month, int day, int dayOfWeek, int millis, int monthLength, int prevMonthLength)
void
getOffsetFromLocal(long date, BasicTimeZone.LocalOption nonExistingTimeOpt, BasicTimeZone.LocalOption duplicatedTimeOpt, int[] offsets)
Returns time zone offsets from local wall time.TimeZoneTransition
getPreviousTransition(long base, boolean inclusive)
Returns the last time zone transition before the base time.int
getRawOffset()
Overrides TimeZone Gets the GMT offset for this time zone.private STZInfo
getSTZInfo()
TimeZoneRule[]
getTimeZoneRules()
Returns the array ofTimeZoneRule
which represents the rule of this time zone object.int
hashCode()
Overrides hashCode.boolean
hasSameRules(TimeZone othr)
Returns true if this zone has the same rules and offset as another zone.private boolean
idEquals(java.lang.String id1, java.lang.String id2)
boolean
inDaylightTime(java.util.Date date)
Overrides TimeZone Queries if the give date is in Daylight Saving Time.private void
initTransitionRules()
boolean
isFrozen()
Determines whether the object has been frozen or not.boolean
observesDaylightTime()
Queries if this time zone is in daylight saving time or will observe daylight saving time at any future time.private void
readObject(java.io.ObjectInputStream in)
Returns the java.util.SimpleTimeZone that this class wraps.void
setDSTSavings(int millisSavedDuringDST)
Sets the amount of time in ms that the clock is advanced during DST.void
setEndRule(int month, int dayOfMonth, int time)
Sets the DST end rule to a fixed date within a month.void
setEndRule(int month, int dayOfWeekInMonth, int dayOfWeek, int time)
Sets the daylight savings ending rule.void
setEndRule(int month, int dayOfMonth, int dayOfWeek, int time, boolean after)
Sets the DST end rule to a weekday before or after a give date within a month, e.g., the first Monday on or after the 8th.private void
setEndRule(int month, int dayOfWeekInMonth, int dayOfWeek, int time, int mode)
Sets the daylight savings ending rule.private void
setEndRule(int month, int dayOfMonth, int dayOfWeek, int time, int mode, boolean after)
void
setID(java.lang.String ID)
Sets the time zone ID.void
setRawOffset(int offsetMillis)
Overrides TimeZone Sets the base time zone offset to GMT.void
setStartRule(int month, int dayOfMonth, int time)
Sets the DST start rule to a fixed date within a month.void
setStartRule(int month, int dayOfWeekInMonth, int dayOfWeek, int time)
Sets the daylight savings starting rule.void
setStartRule(int month, int dayOfMonth, int dayOfWeek, int time, boolean after)
Sets the DST start rule to a weekday before or after a give date within a month, e.g., the first Monday on or after the 8th.private void
setStartRule(int month, int dayOfWeekInMonth, int dayOfWeek, int time, int mode)
Sets the daylight savings starting rule.void
setStartYear(int year)
Sets the daylight savings starting year.java.lang.String
toString()
Returns a string representation of this object.boolean
useDaylightTime()
Overrides TimeZone Queries if this time zone uses Daylight Saving Time.-
Methods inherited from class com.ibm.icu.util.BasicTimeZone
getLocalOptionValue, getSimpleTimeZoneRulesNear, getTimeZoneRules, hasEquivalentTransitions, hasEquivalentTransitions
-
Methods inherited from class com.ibm.icu.util.TimeZone
countEquivalentIDs, forLocaleOrDefault, forULocaleOrDefault, getAvailableIDs, getAvailableIDs, getAvailableIDs, getAvailableIDs, getCanonicalID, getCanonicalID, getDefault, getDefaultTimeZoneType, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getEquivalentID, getFrozenICUTimeZone, getFrozenTimeZone, getIanaID, getID, getIDForWindowsID, getOffset, getOffset, getRegion, getTimeZone, getTimeZone, getTZDataVersion, getWindowsID, setDefault, setDefaultTimeZoneType, setICUDefault
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
WALL_TIME
public static final int WALL_TIME
Constant for a mode of start or end time specified as local wall time.- See Also:
- Constant Field Values
-
STANDARD_TIME
public static final int STANDARD_TIME
Constant for a mode of start or end time specified as local standard time.- See Also:
- Constant Field Values
-
UTC_TIME
public static final int UTC_TIME
Constant for a mode of start or end time specified as UTC.- See Also:
- Constant Field Values
-
staticMonthLength
private static final byte[] staticMonthLength
-
DOM_MODE
private static final int DOM_MODE
- See Also:
- Constant Field Values
-
DOW_IN_MONTH_MODE
private static final int DOW_IN_MONTH_MODE
- See Also:
- Constant Field Values
-
DOW_GE_DOM_MODE
private static final int DOW_GE_DOM_MODE
- See Also:
- Constant Field Values
-
DOW_LE_DOM_MODE
private static final int DOW_LE_DOM_MODE
- See Also:
- Constant Field Values
-
raw
private int raw
-
dst
private int dst
-
xinfo
private STZInfo xinfo
-
startMonth
private int startMonth
-
startDay
private int startDay
-
startDayOfWeek
private int startDayOfWeek
-
startTime
private int startTime
-
startTimeMode
private int startTimeMode
-
endTimeMode
private int endTimeMode
-
endMonth
private int endMonth
-
endDay
private int endDay
-
endDayOfWeek
private int endDayOfWeek
-
endTime
private int endTime
-
startYear
private int startYear
-
useDaylight
private boolean useDaylight
-
startMode
private int startMode
-
endMode
private int endMode
-
transitionRulesInitialized
private transient boolean transitionRulesInitialized
-
initialRule
private transient InitialTimeZoneRule initialRule
-
firstTransition
private transient TimeZoneTransition firstTransition
-
stdRule
private transient AnnualTimeZoneRule stdRule
-
dstRule
private transient AnnualTimeZoneRule dstRule
-
isFrozen
private transient volatile boolean isFrozen
-
-
Constructor Detail
-
SimpleTimeZone
public SimpleTimeZone(int rawOffset, java.lang.String ID)
Constructs a SimpleTimeZone with the given base time zone offset from GMT and time zone ID. Timezone IDs can be obtained from TimeZone.getAvailableIDs. Normally you should use TimeZone.getDefault to construct a TimeZone.- Parameters:
rawOffset
- The given base time zone offset to GMT.ID
- The time zone ID which is obtained from TimeZone.getAvailableIDs.
-
SimpleTimeZone
public SimpleTimeZone(int rawOffset, java.lang.String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int endMonth, int endDay, int endDayOfWeek, int endTime)
Constructs a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, time to start and end the daylight time. Timezone IDs can be obtained from TimeZone.getAvailableIDs. Normally you should use TimeZone.getDefault to create a TimeZone. For a time zone that does not use daylight saving time, do not use this constructor; instead you should use SimpleTimeZone(rawOffset, ID). By default, this constructor specifies day-of-week-in-month rules. That is, if the startDay is 1, and the startDayOfWeek is SUNDAY, then this indicates the first Sunday in the startMonth. A startDay of -1 likewise indicates the last Sunday. However, by using negative or zero values for certain parameters, other types of rules can be specified. Day of month. To specify an exact day of the month, such as March 1, set startDayOfWeek to zero. Day of week after day of month. To specify the first day of the week occurring on or after an exact day of the month, make the day of the week negative. For example, if startDay is 5 and startDayOfWeek is -MONDAY, this indicates the first Monday on or after the 5th day of the startMonth. Day of week before day of month. To specify the last day of the week occurring on or before an exact day of the month, make the day of the week and the day of the month negative. For example, if startDay is -21 and startDayOfWeek is -WEDNESDAY, this indicates the last Wednesday on or before the 21st of the startMonth. The above examples refer to the startMonth, startDay, and startDayOfWeek; the same applies for the endMonth, endDay, and endDayOfWeek.- Parameters:
rawOffset
- The given base time zone offset to GMT.ID
- The time zone ID which is obtained from TimeZone.getAvailableIDs.startMonth
- The daylight savings starting month. Month is 0-based. eg, 0 for January.startDay
- The daylight savings starting day-of-week-in-month. Please see the member description for an example.startDayOfWeek
- The daylight savings starting day-of-week. Please see the member description for an example.startTime
- The daylight savings starting time in local wall time, which is standard time in this case. Please see the member description for an example.endMonth
- The daylight savings ending month. Month is 0-based. eg, 0 for January.endDay
- The daylight savings ending day-of-week-in-month. Please see the member description for an example.endDayOfWeek
- The daylight savings ending day-of-week. Please see the member description for an example.endTime
- The daylight savings ending time in local wall time, which is daylight time in this case. Please see the member description for an example.- Throws:
java.lang.IllegalArgumentException
- the month, day, dayOfWeek, or time parameters are out of range for the start or end rule
-
SimpleTimeZone
public SimpleTimeZone(int rawOffset, java.lang.String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int startTimeMode, int endMonth, int endDay, int endDayOfWeek, int endTime, int endTimeMode, int dstSavings)
Constructs a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, time and its mode to start and end the daylight time. The mode specifies eitherWALL_TIME
orSTANDARD_TIME
orUTC_TIME
.- Parameters:
rawOffset
- The given base time zone offset to GMT.ID
- The time zone ID which is obtained from TimeZone.getAvailableIDs.startMonth
- The daylight savings starting month. Month is 0-based. eg, 0 for January.startDay
- The daylight savings starting day-of-week-in-month. Please see the member description for an example.startDayOfWeek
- The daylight savings starting day-of-week. Please see the member description for an example.startTime
- The daylight savings starting time in local wall time, which is standard time in this case. Please see the member description for an example.startTimeMode
- The mode of the start time specified by startTime.endMonth
- The daylight savings ending month. Month is 0-based. eg, 0 for January.endDay
- The daylight savings ending day-of-week-in-month. Please see the member description for an example.endDayOfWeek
- The daylight savings ending day-of-week. Please see the member description for an example.endTime
- The daylight savings ending time in local wall time, which is daylight time in this case. Please see the member description for an example.endTimeMode
- The mode of the end time specified by endTime.dstSavings
- The amount of time in ms saved during DST.- Throws:
java.lang.IllegalArgumentException
- the month, day, dayOfWeek, or time parameters are out of range for the start or end rule
-
SimpleTimeZone
public SimpleTimeZone(int rawOffset, java.lang.String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int endMonth, int endDay, int endDayOfWeek, int endTime, int dstSavings)
Constructor. This constructor is identical to the 10-argument constructor, but also takes a dstSavings parameter.- Parameters:
rawOffset
- The given base time zone offset to GMT.ID
- The time zone ID which is obtained from TimeZone.getAvailableIDs.startMonth
- The daylight savings starting month. Month is 0-based. eg, 0 for January.startDay
- The daylight savings starting day-of-week-in-month. Please see the member description for an example.startDayOfWeek
- The daylight savings starting day-of-week. Please see the member description for an example.startTime
- The daylight savings starting time in local wall time, which is standard time in this case. Please see the member description for an example.endMonth
- The daylight savings ending month. Month is 0-based. eg, 0 for January.endDay
- The daylight savings ending day-of-week-in-month. Please see the member description for an example.endDayOfWeek
- The daylight savings ending day-of-week. Please see the member description for an example.endTime
- The daylight savings ending time in local wall time, which is daylight time in this case. Please see the member description for an example.dstSavings
- The amount of time in ms saved during DST.- Throws:
java.lang.IllegalArgumentException
- the month, day, dayOfWeek, or time parameters are out of range for the start or end rule
-
-
Method Detail
-
setID
public void setID(java.lang.String ID)
Sets the time zone ID. This does not change any other data in the time zone object.
-
setRawOffset
public void setRawOffset(int offsetMillis)
Overrides TimeZone Sets the base time zone offset to GMT. This is the offset to add "to" UTC to get local time.- Specified by:
setRawOffset
in classTimeZone
- Parameters:
offsetMillis
- the raw offset of the time zone
-
getRawOffset
public int getRawOffset()
Overrides TimeZone Gets the GMT offset for this time zone.- Specified by:
getRawOffset
in classTimeZone
- Returns:
- the raw offset
-
setStartYear
public void setStartYear(int year)
Sets the daylight savings starting year.- Parameters:
year
- The daylight savings starting year.
-
setStartRule
public void setStartRule(int month, int dayOfWeekInMonth, int dayOfWeek, int time)
Sets the daylight savings starting rule. For example, Daylight Savings Time starts at the second Sunday in March, at 2 AM in standard time. Therefore, you can set the start rule by calling: setStartRule(Calendar.MARCH, 2, Calendar.SUNDAY, 2*60*60*1000);- Parameters:
month
- The daylight savings starting month. Month is 0-based. eg, 0 for January.dayOfWeekInMonth
- The daylight savings starting day-of-week-in-month. Please see the member description for an example.dayOfWeek
- The daylight savings starting day-of-week. Please see the member description for an example.time
- The daylight savings starting time in local wall time, which is standard time in this case. Please see the member description for an example.- Throws:
java.lang.IllegalArgumentException
- the month, dayOfWeekInMonth, dayOfWeek, or time parameters are out of range
-
setStartRule
private void setStartRule(int month, int dayOfWeekInMonth, int dayOfWeek, int time, int mode)
Sets the daylight savings starting rule. For example, in the U.S., Daylight Savings Time starts at the second Sunday in March, at 2 AM in standard time. Therefore, you can set the start rule by calling:setStartRule(Calendar.MARCH, 2, Calendar.SUNDAY, 2*60*60*1000);
The dayOfWeekInMonth and dayOfWeek parameters together specify how to calculate the exact starting date. Their exact meaning depend on their respective signs, allowing various types of rules to be constructed, as follows:- If both dayOfWeekInMonth and dayOfWeek are positive, they specify the day of week in the month (e.g., (2, WEDNESDAY) is the second Wednesday of the month).
- If dayOfWeek is positive and dayOfWeekInMonth is negative, they specify the day of week in the month counting backward from the end of the month. (e.g., (-1, MONDAY) is the last Monday in the month)
- If dayOfWeek is zero and dayOfWeekInMonth is positive, dayOfWeekInMonth specifies the day of the month, regardless of what day of the week it is. (e.g., (10, 0) is the tenth day of the month)
- If dayOfWeek is zero and dayOfWeekInMonth is negative, dayOfWeekInMonth specifies the day of the month counting backward from the end of the month, regardless of what day of the week it is (e.g., (-2, 0) is the next-to-last day of the month).
- If dayOfWeek is negative and dayOfWeekInMonth is positive, they specify the first specified day of the week on or after the specified day of the month. (e.g., (15, -SUNDAY) is the first Sunday after the 15th of the month [or the 15th itself if the 15th is a Sunday].)
- If dayOfWeek and DayOfWeekInMonth are both negative, they specify the last specified day of the week on or before the specified day of the month. (e.g., (-20, -TUESDAY) is the last Tuesday before the 20th of the month [or the 20th itself if the 20th is a Tuesday].)
- Parameters:
month
- the daylight savings starting month. Month is 0-based. eg, 0 for January.dayOfWeekInMonth
- the daylight savings starting day-of-week-in-month. Please see the member description for an example.dayOfWeek
- the daylight savings starting day-of-week. Please see the member description for an example.time
- the daylight savings starting time. Please see the member description for an example.
-
setStartRule
public void setStartRule(int month, int dayOfMonth, int time)
Sets the DST start rule to a fixed date within a month.- Parameters:
month
- The month in which this rule occurs (0-based).dayOfMonth
- The date in that month (1-based).time
- The time of that day (number of millis after midnight) when DST takes effect in local wall time, which is standard time in this case.- Throws:
java.lang.IllegalArgumentException
- the month, dayOfMonth, or time parameters are out of range
-
setStartRule
public void setStartRule(int month, int dayOfMonth, int dayOfWeek, int time, boolean after)
Sets the DST start rule to a weekday before or after a give date within a month, e.g., the first Monday on or after the 8th.- Parameters:
month
- The month in which this rule occurs (0-based).dayOfMonth
- A date within that month (1-based).dayOfWeek
- The day of the week on which this rule occurs.time
- The time of that day (number of millis after midnight) when DST takes effect in local wall time, which is standard time in this case.after
- If true, this rule selects the first dayOfWeek on or after dayOfMonth. If false, this rule selects the last dayOfWeek on or before dayOfMonth.- Throws:
java.lang.IllegalArgumentException
- the month, dayOfMonth, dayOfWeek, or time parameters are out of range
-
setEndRule
public void setEndRule(int month, int dayOfWeekInMonth, int dayOfWeek, int time)
Sets the daylight savings ending rule. For example, if Daylight Savings Time ends at the last (-1) Sunday in October, at 2 AM in standard time, you can set the end rule by calling:setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2*60*60*1000);
- Parameters:
month
- The daylight savings ending month. Month is 0-based. eg, 0 for January.dayOfWeekInMonth
- The daylight savings ending day-of-week-in-month. Please see the member description for an example.dayOfWeek
- The daylight savings ending day-of-week. Please see the member description for an example.time
- The daylight savings ending time in local wall time, which is daylight time in this case. Please see the member description for an example.- Throws:
java.lang.IllegalArgumentException
- the month, dayOfWeekInMonth, dayOfWeek, or time parameters are out of range
-
setEndRule
public void setEndRule(int month, int dayOfMonth, int time)
Sets the DST end rule to a fixed date within a month.- Parameters:
month
- The month in which this rule occurs (0-based).dayOfMonth
- The date in that month (1-based).time
- The time of that day (number of millis after midnight) when DST ends in local wall time, which is daylight time in this case.- Throws:
java.lang.IllegalArgumentException
- the month, dayOfMonth, or time parameters are out of range
-
setEndRule
public void setEndRule(int month, int dayOfMonth, int dayOfWeek, int time, boolean after)
Sets the DST end rule to a weekday before or after a give date within a month, e.g., the first Monday on or after the 8th.- Parameters:
month
- The month in which this rule occurs (0-based).dayOfMonth
- A date within that month (1-based).dayOfWeek
- The day of the week on which this rule occurs.time
- The time of that day (number of millis after midnight) when DST ends in local wall time, which is daylight time in this case.after
- If true, this rule selects the first dayOfWeek on or after dayOfMonth. If false, this rule selects the last dayOfWeek on or before dayOfMonth.- Throws:
java.lang.IllegalArgumentException
- the month, dayOfMonth, dayOfWeek, or time parameters are out of range
-
setEndRule
private void setEndRule(int month, int dayOfMonth, int dayOfWeek, int time, int mode, boolean after)
-
setEndRule
private void setEndRule(int month, int dayOfWeekInMonth, int dayOfWeek, int time, int mode)
Sets the daylight savings ending rule. For example, in the U.S., Daylight Savings Time ends at the first Sunday in November, at 2 AM in standard time. Therefore, you can set the end rule by calling: setEndRule(Calendar.NOVEMBER, 1, Calendar.SUNDAY, 2*60*60*1000); Various other types of rules can be specified by manipulating the dayOfWeek and dayOfWeekInMonth parameters. For complete details, see the documentation for setStartRule().- Parameters:
month
- the daylight savings ending month. Month is 0-based. eg, 0 for January.dayOfWeekInMonth
- the daylight savings ending day-of-week-in-month. See setStartRule() for a complete explanation.dayOfWeek
- the daylight savings ending day-of-week. See setStartRule() for a complete explanation.time
- the daylight savings ending time. Please see the member description for an example.
-
setDSTSavings
public void setDSTSavings(int millisSavedDuringDST)
Sets the amount of time in ms that the clock is advanced during DST.- Parameters:
millisSavedDuringDST
- the number of milliseconds the time is advanced with respect to standard time when the daylight savings rules are in effect. Typically one hour (+3600000). The amount could be negative, but not 0.
-
getDSTSavings
public int getDSTSavings()
Returns the amount of time in ms that the clock is advanced during DST.- Overrides:
getDSTSavings
in classTimeZone
- Returns:
- the number of milliseconds the time is advanced with respect to standard time when the daylight savings rules are in effect. Typically one hour (3600000). The amount could be negative, but not 0.
-
readObject
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException
Returns the java.util.SimpleTimeZone that this class wraps. java.util.SimpleTimeZone unwrapSTZ() { return (java.util.SimpleTimeZone) unwrap(); }- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
toString
public java.lang.String toString()
Returns a string representation of this object.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a string representation of this object
-
getSTZInfo
private STZInfo getSTZInfo()
-
getOffset
public int getOffset(int era, int year, int month, int day, int dayOfWeek, int millis)
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 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.millis
- the millis in day in standard local time.- Returns:
- the offset to add to GMT to get local time.
-
getOffset
@Deprecated public int getOffset(int era, int year, int month, int day, int dayOfWeek, int millis, int monthLength)
Deprecated.This API is ICU internal only.
-
getOffset
private int getOffset(int era, int year, int month, int day, int dayOfWeek, int millis, int monthLength, int prevMonthLength)
-
getOffsetFromLocal
public void getOffsetFromLocal(long date, BasicTimeZone.LocalOption nonExistingTimeOpt, BasicTimeZone.LocalOption duplicatedTimeOpt, int[] offsets)
Returns time zone offsets from local wall time.- Overrides:
getOffsetFromLocal
in classBasicTimeZone
-
compareToRule
private int compareToRule(int month, int monthLen, int prevMonthLen, int dayOfMonth, int dayOfWeek, int millis, int millisDelta, int ruleMode, int ruleMonth, int ruleDayOfWeek, int ruleDay, int ruleMillis)
Compare a given date in the year to a rule. Return 1, 0, or -1, depending on whether the date is after, equal to, or before the rule date. The millis are compared directly against the ruleMillis, so any standard-daylight adjustments must be handled by the caller.- Returns:
- 1 if the date is after the rule date, -1 if the date is before the rule date, or 0 if the date is equal to the rule date.
-
useDaylightTime
public boolean useDaylightTime()
Overrides TimeZone Queries if this time zone uses Daylight Saving Time.- Specified by:
useDaylightTime
in 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
false
for such case. The default implementation of this method returnstrue
when 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
true
ifTimeZone.useDaylightTime()
orinDaylightTime(new Date())
returnstrue
.Note: This method was added for
TimeZone
compatibility support. TheTimeZone.useDaylightTime()
method only checks the last known rule(s), therefore it may return false even the zone observes daylight saving time currently.TimeZone
addedobservesDaylightTime()
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 returnfalse
if 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 returnfalse
even whenTimeZone.useDaylightTime()
returnstrue
.- Overrides:
observesDaylightTime
in classTimeZone
- Returns:
true
if this time zone is in daylight saving time or will observe daylight saving time at any future time.- See Also:
TimeZone.useDaylightTime()
-
inDaylightTime
public boolean inDaylightTime(java.util.Date date)
Overrides TimeZone Queries if the give date is in Daylight Saving Time.- Specified by:
inDaylightTime
in classTimeZone
- Parameters:
date
- the given Date.- Returns:
- true if the given date is in daylight savings time, false, otherwise.
-
construct
private void construct(int _raw, int _startMonth, int _startDay, int _startDayOfWeek, int _startTime, int _startTimeMode, int _endMonth, int _endDay, int _endDayOfWeek, int _endTime, int _endTimeMode, int _dst)
Internal construction method.
-
decodeRules
private void decodeRules()
-
decodeStartRule
private void decodeStartRule()
Decode the start rule and validate the parameters. The parameters are expected to be in encoded form, which represents the various rule modes by negating or zeroing certain values. Representation formats are:DOW_IN_MONTH DOM DOW>=DOM DOW<=DOM no DST ------------ ----- -------- -------- ---------- month 0..11 same same same don't care day -5..5 1..31 1..31 -1..-31 0 dayOfWeek 1..7 0 -1..-7 -1..-7 don't care time 0..ONEDAY same same same don't care
The range for month does not include UNDECIMBER since this class is really specific to GregorianCalendar, which does not use that month. The range for time includes ONEDAY (vs. ending at ONEDAY-1) because the end rule is an exclusive limit point. That is, the range of times that are in DST include those >= the start and < the end. For this reason, it should be possible to specify an end of ONEDAY in order to include the entire day. Although this is equivalent to time 0 of the following day, it's not always possible to specify that, for example, on December 31. While arguably the start range should still be 0..ONEDAY-1, we keep the start and end ranges the same for consistency.
-
decodeEndRule
private void decodeEndRule()
Decode the end rule and validate the parameters. This method is exactly analogous to decodeStartRule().- See Also:
decodeStartRule()
-
equals
public boolean equals(java.lang.Object obj)
Overrides equals.
-
idEquals
private boolean idEquals(java.lang.String id1, java.lang.String id2)
-
hashCode
public int hashCode()
Overrides hashCode.
-
hasSameRules
public boolean hasSameRules(TimeZone othr)
Returns true if this zone has the same rules and offset as another zone.- Overrides:
hasSameRules
in classTimeZone
- Parameters:
othr
- the TimeZone object to be compared with- Returns:
- true if the given zone has the same rules and offset as this one
-
getNextTransition
public TimeZoneTransition getNextTransition(long base, boolean inclusive)
Returns the first time zone transition after the base time.Example code:{@.jcite com.ibm.icu.samples.util.timezone.BasicTimeZoneExample:---getNextTransitionExample}
- Specified by:
getNextTransition
in classBasicTimeZone
- 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.
-
getPreviousTransition
public TimeZoneTransition getPreviousTransition(long base, boolean inclusive)
Returns the last time zone transition before the base time.Example code:{@.jcite com.ibm.icu.samples.util.timezone.BasicTimeZoneExample:---getPreviousTransitionExample}
- Specified by:
getPreviousTransition
in classBasicTimeZone
- 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.
-
getTimeZoneRules
public TimeZoneRule[] getTimeZoneRules()
Returns the array ofTimeZoneRule
which represents the rule of this time zone object. The first element in the result array will be theInitialTimeZoneRule
instance for the initial rule. The rest will be eitherAnnualTimeZoneRule
orTimeArrayTimeZoneRule
instances representing transitions.- Specified by:
getTimeZoneRules
in classBasicTimeZone
- Returns:
- The array of
TimeZoneRule
which represents this time zone.
-
initTransitionRules
private void initTransitionRules()
-
isFrozen
public boolean isFrozen()
Determines whether the object has been frozen or not.
-
freeze
public TimeZone freeze()
Freezes the object.
-
cloneAsThawed
public TimeZone cloneAsThawed()
Provides for the clone operation. Any clone is initially unfrozen.- Specified by:
cloneAsThawed
in interfaceFreezable<TimeZone>
- Overrides:
cloneAsThawed
in classTimeZone
-
-