com.ibm.icu.util

Class SimpleTimeZone

Implemented Interfaces:
Cloneable, Serializable

public class SimpleTimeZone
extends com.ibm.icu.impl.JDKTimeZone

SimpleTimeZone is a concrete subclass of TimeZone 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 that SimpleTimeZone should count from the end of the month backwards. For example, Daylight Savings Time ends at the last (dayOfWeekInMonth = -1) Sunday in October, at 2 AM in standard time.

Author:
David Goldsmith, Mark Davis, Chen-Lieh Huang, Alan Liu
See Also:
Calendar, GregorianCalendar, TimeZone

Field Summary

Fields inherited from class com.ibm.icu.impl.JDKTimeZone

zone

Fields inherited from class com.ibm.icu.util.TimeZone

LONG, MILLIS_PER_DAY, MILLIS_PER_HOUR, SHORT

Constructor Summary

SimpleTimeZone(int rawOffset, String ID)
Constructs a SimpleTimeZone with the given base time zone offset from GMT and time zone ID.
SimpleTimeZone(int rawOffset, String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int endMonth, int endDay, int endDayOfWeek, int endTime)
Construct 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, String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int endMonth, int endDay, int endDayOfWeek, int endTime, int dstSavings)
Constructor.
SimpleTimeZone(int raw, String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int startTimeMode, int endMonth, int endDay, int endDayOfWeek, int endTime, int endTimeMode, int dst)
SimpleTimeZone(SimpleTimeZone tz, String ID)
Constructs a SimpleTimeZone that wraps the given java.util.SimpleTimeZone.

Method Summary

Object
clone()
Return a clone of this time zone.
boolean
equals(Object obj)
Return true if obj is a SimpleTimeZone equivalent to this.
int
getDSTSavings()
Returns the amount of time in ms that the clock is advanced during DST.
int
getOffset(int era, int year, int month, int day, int dayOfWeek, int millis)
int
getOffset(int era, int year, int month, int day, int dayOfWeek, int millis, int monthLength)
int
getRawOffset()
get the raw offset.
boolean
hasSameRules(TimeZone othr)
int
hashCode()
Return the hash code.
boolean
inDaylightTime(Date date)
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.
void
setRawOffset(int offsetMillis)
Set the raw offset.
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.
void
setStartYear(int year)
Sets the daylight savings starting year.
String
toString()
Returns a string representation of this object.
boolean
useDaylightTime()

Methods inherited from class com.ibm.icu.impl.JDKTimeZone

clone, equals, getDSTSavings, getOffset, getOffset, getRawOffset, hasSameRules, hashCode, inDaylightTime, setID, setRawOffset, toString, useDaylightTime, wrap

Methods inherited from class com.ibm.icu.util.TimeZone

clone, countEquivalentIDs, equals, getAvailableIDs, getAvailableIDs, getAvailableIDs, getDSTSavings, getDefault, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getEquivalentID, getID, getOffset, getOffset, getOffset, getRawOffset, getTimeZone, hasSameRules, hashCode, inDaylightTime, setDefault, setID, setRawOffset, useDaylightTime

Constructor Details

SimpleTimeZone

public SimpleTimeZone(int rawOffset,
                      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,
                      String ID,
                      int startMonth,
                      int startDay,
                      int startDayOfWeek,
                      int startTime,
                      int endMonth,
                      int endDay,
                      int endDayOfWeek,
                      int endTime)
Construct 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.

SimpleTimeZone

public SimpleTimeZone(int rawOffset,
                      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:
dstSavings - The amount of time in ms saved during DST.

SimpleTimeZone

public SimpleTimeZone(int raw,
                      String ID,
                      int startMonth,
                      int startDay,
                      int startDayOfWeek,
                      int startTime,
                      int startTimeMode,
                      int endMonth,
                      int endDay,
                      int endDayOfWeek,
                      int endTime,
                      int endTimeMode,
                      int dst)

SimpleTimeZone

public SimpleTimeZone(SimpleTimeZone tz,
                      String ID)
Constructs a SimpleTimeZone that wraps the given java.util.SimpleTimeZone. Do not call; use the TimeZone API.

Method Details

clone

public Object clone()
Return a clone of this time zone.
Overrides:
clone in interface com.ibm.icu.impl.JDKTimeZone
Returns:
a clone of this time zone

equals

public boolean equals(Object obj)
Return true if obj is a SimpleTimeZone equivalent to this.
Overrides:
equals in interface com.ibm.icu.impl.JDKTimeZone
Returns:
true if obj is a SimpleTimeZone equivalent to this

getDSTSavings

public int getDSTSavings()
Returns the amount of time in ms that the clock is advanced during DST.
Overrides:
getDSTSavings in interface com.ibm.icu.impl.JDKTimeZone
Returns:
the number of milliseconds the time is advanced with respect to standard time when the daylight savings rules are in effect. A positive number, typically one hour (3600000).

getOffset

public int getOffset(int era,
                     int year,
                     int month,
                     int day,
                     int dayOfWeek,
                     int millis)
Overrides:
getOffset in interface com.ibm.icu.impl.JDKTimeZone

getOffset

public int getOffset(int era,
                     int year,
                     int month,
                     int day,
                     int dayOfWeek,
                     int millis,
                     int monthLength)

getRawOffset

public int getRawOffset()
get the raw offset.
Overrides:
getRawOffset in interface com.ibm.icu.impl.JDKTimeZone
Returns:
the raw offset

hasSameRules

public boolean hasSameRules(TimeZone othr)
Overrides:
hasSameRules in interface com.ibm.icu.impl.JDKTimeZone

hashCode

public int hashCode()
Return the hash code.
Overrides:
hashCode in interface com.ibm.icu.impl.JDKTimeZone
Returns:
the hash code

inDaylightTime

public boolean inDaylightTime(Date date)
Overrides:
inDaylightTime in interface com.ibm.icu.impl.JDKTimeZone

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. A positive number, typically one hour (3600000).

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.

setEndRule

public void setEndRule(int month,
                       int dayOfWeekInMonth,
                       int dayOfWeek,
                       int time)
Sets the daylight savings ending rule. For example, Daylight Savings Time ends at the last (-1) Sunday in October, at 2 AM in standard time. Therefore, you can set the end rule by calling: setEndRule(TimeFields.OCTOBER, -1, TimeFields.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.

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.

setRawOffset

public void setRawOffset(int offsetMillis)
Set the raw offset.
Overrides:
setRawOffset in interface com.ibm.icu.impl.JDKTimeZone
Parameters:
offsetMillis - the raw offset of the time zone

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.

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 first Sunday in April, at 2 AM in standard time. Therefore, you can set the start rule by calling: setStartRule(TimeFields.APRIL, 1, TimeFields.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.

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.

setStartYear

public void setStartYear(int year)
Sets the daylight savings starting year.
Parameters:
year - The daylight savings starting year.

toString

public String toString()
Returns a string representation of this object.
Overrides:
toString in interface com.ibm.icu.impl.JDKTimeZone
Returns:
a string representation of this object

useDaylightTime

public boolean useDaylightTime()
Overrides:
useDaylightTime in interface com.ibm.icu.impl.JDKTimeZone

Copyright (c) 2006 IBM Corporation and others.