|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.TimeZone | +--java.util.SimpleTimeZone
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.
Calendar
,
GregorianCalendar
,
TimeZone
, Serialized FormField Summary | |
(package private) static int |
currentSerialVersion
|
private static int |
DOM_MODE
Constants specifying values of startMode and endMode. |
private static int |
DOW_GE_DOM_MODE
|
private static int |
DOW_IN_MONTH_MODE
|
private static int |
DOW_LE_DOM_MODE
|
private int |
dstSavings
A positive value indicating the amount of time saved during DST in milliseconds. |
private int |
endDay
This field has two possible interpretations: endMode == DOW_IN_MONTH
endDay indicates the day of the month of
endMonth on which daylight
savings time ends, from 1 to 28, 30, or 31, depending on the
endMonth . |
private int |
endDayOfWeek
The day of the week on which daylight savings time ends. |
private int |
endMode
Variables specifying the mode of the end rule. |
private int |
endMonth
The month in which daylight savings time ends. |
private int |
endTime
The time in milliseconds after midnight at which daylight savings time ends. |
private static int |
millisPerDay
|
private static int |
millisPerHour
|
private byte[] |
monthLength
This field was serialized in JDK 1.1, so we have to keep it that way to maintain serialization compatibility. |
private int |
rawOffset
The offset in milliseconds between this zone and GMT. |
private int |
serialVersionOnStream
The version of the serialized data on the stream. |
(package private) static long |
serialVersionUID
|
private int |
startDay
This field has two possible interpretations: startMode == DOW_IN_MONTH
startDay indicates the day of the month of
startMonth on which daylight
savings time starts, from 1 to 28, 30, or 31, depending on the
startMonth . |
private int |
startDayOfWeek
The day of the week on which daylight savings time starts. |
private int |
startMode
Variables specifying the mode of the start rule. |
private int |
startMonth
The month in which daylight savings time starts. |
private int |
startTime
The time in milliseconds after midnight at which daylight savings time starts. |
private int |
startYear
The year in which daylight savings time is first observed. |
private static byte[] |
staticMonthLength
|
private boolean |
useDaylight
A boolean value which is true if and only if this zone uses daylight savings time. |
Fields inherited from class java.util.TimeZone |
cachedLocaleData,
CUSTOM_ID,
defaultZone,
GMT,
GMT_ID,
GMT_ID_LENGTH,
ID,
LONG,
numberFormat,
ONE_DAY,
ONE_HOUR,
ONE_MINUTE,
serialVersionUID,
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. |
Method Summary | |
Object |
clone()
Overrides Cloneable |
private static int |
compareToRule(int month,
int monthLen,
int dayOfMonth,
int dayOfWeek,
int millis,
int ruleMode,
int ruleMonth,
int ruleDayOfWeek,
int ruleDay,
int ruleMillis)
Compare a given date in the year to a rule. |
private void |
decodeEndRule()
Decode the end rule and validate the parameters. |
private void |
decodeRules()
Given a set of encoded rules in startDay and startDayOfMonth, decode them and set the startMode appropriately. |
private void |
decodeStartRule()
Decode the start rule and validate the parameters. |
boolean |
equals(Object obj)
Compares the equality of two SimpleTimeZone objects. |
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)
Overrides TimeZone Gets offset, for current date, modified in case of daylight savings. |
(package private) int |
getOffset(int era,
int year,
int month,
int day,
int dayOfWeek,
int millis,
int monthLength)
Gets offset, for current date, modified in case of daylight savings. |
int |
getRawOffset()
Overrides TimeZone Gets the GMT offset for this time zone. |
int |
hashCode()
Override hashCode. |
boolean |
hasSameRules(TimeZone other)
Return true if this zone has the same rules and offset as another zone. |
boolean |
inDaylightTime(Date date)
Overrides TimeZone Queries if the given date is in Daylight Savings Time. |
private void |
makeRulesCompatible()
Make rules compatible to 1.1 FCS code. |
private byte[] |
packRules()
Pack the start and end rules into an array of bytes. |
private void |
readObject(ObjectInputStream stream)
Reconstitute this object from a stream (i.e., deserialize it). |
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)
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. |
void |
setStartYear(int year)
Sets the daylight savings starting year. |
String |
toString()
Return a string representation of this time zone. |
private void |
unpackRules(byte[] rules)
Given an array of bytes produced by packRules, interpret them as the start and end rules. |
boolean |
useDaylightTime()
Overrides TimeZone Queries if this time zone uses Daylight Savings Time. |
private void |
writeObject(ObjectOutputStream stream)
Save the state of this object to a stream (i.e., serialize it). |
Methods inherited from class java.util.TimeZone |
getAvailableIDs,
getAvailableIDs,
getDefault,
getDisplayName,
getDisplayName,
getDisplayName,
getDisplayName,
getID,
getTimeZone,
parseCustomTimeZone,
setDefault,
setID |
Methods inherited from class java.lang.Object |
|
Field Detail |
private int startMonth
Calendar.JANUARY
and
Calendar.DECEMBER
inclusive. This value must not equal
endMonth
.
If useDaylight
is false, this value is ignored.
private int startDay
startMode == DOW_IN_MONTH
startDay
indicates the day of the month of
startMonth
on which daylight
savings time starts, from 1 to 28, 30, or 31, depending on the
startMonth
.
startMode != DOW_IN_MONTH
startDay
indicates which startDayOfWeek
in th
month startMonth
daylight
savings time starts on. For example, a value of +1 and a
startDayOfWeek
of Calendar.SUNDAY
indicates the
first Sunday of startMonth
. Likewise, +2 would indicate the
second Sunday, and -1 the last Sunday. A value of 0 is illegal.
If useDaylight
is false, this value is ignored.
private int startDayOfWeek
Calendar.SUNDAY
and
Calendar.SATURDAY
inclusive.
If useDaylight
is false or
startMode == DAY_OF_MONTH
, this value is ignored.
private int startTime
If useDaylight
is false, this value is ignored.
private int endMonth
Calendar.JANUARY
and
Calendar.UNDECIMBER
. This value must not equal
startMonth
.
If useDaylight
is false, this value is ignored.
private int endDay
endMode == DOW_IN_MONTH
endDay
indicates the day of the month of
endMonth
on which daylight
savings time ends, from 1 to 28, 30, or 31, depending on the
endMonth
.
endMode != DOW_IN_MONTH
endDay
indicates which endDayOfWeek
in th
month endMonth
daylight
savings time ends on. For example, a value of +1 and a
endDayOfWeek
of Calendar.SUNDAY
indicates the
first Sunday of endMonth
. Likewise, +2 would indicate the
second Sunday, and -1 the last Sunday. A value of 0 is illegal.
If useDaylight
is false, this value is ignored.
private int endDayOfWeek
Calendar.SUNDAY
and
Calendar.SATURDAY
inclusive.
If useDaylight
is false or
endMode == DAY_OF_MONTH
, this value is ignored.
private int endTime
If useDaylight
is false, this value is ignored.
private int startYear
If useDaylight
is false, this value is ignored.
private int rawOffset
dstSavings
.private boolean useDaylight
private static final int millisPerHour
private static final int millisPerDay
private final byte[] monthLength
private static final byte[] staticMonthLength
private int startMode
DOM_MODE
DOW_IN_MONTH_MODE
DOW_GE_DOM_MODE
DOW_LE_DOM_MODE
startDay
field.
If useDaylight
is false, this value is ignored.
private int endMode
DOM_MODE
DOW_IN_MONTH_MODE
DOW_GE_DOM_MODE
DOW_LE_DOM_MODE
endDay
field.
If useDaylight
is false, this value is ignored.
private int dstSavings
If useDaylight
is false, this value is ignored.
private static final int DOM_MODE
private static final int DOW_IN_MONTH_MODE
private static final int DOW_GE_DOM_MODE
private static final int DOW_LE_DOM_MODE
static final long serialVersionUID
static final int currentSerialVersion
private int serialVersionOnStream
startMode
,
endMode
, and dstSavings
.
serialVersionOnStream
is written.Constructor Detail |
public SimpleTimeZone(int rawOffset, String ID)
rawOffset
- The given base time zone offset to GMT.ID
- The time zone ID which is obtained from
TimeZone.getAvailableIDs.public SimpleTimeZone(int rawOffset, String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int endMonth, int endDay, int endDayOfWeek, int endTime)
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.public SimpleTimeZone(int rawOffset, String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int endMonth, int endDay, int endDayOfWeek, int endTime, int dstSavings)
dstSavings
- The amount of time in ms saved during DST.Method Detail |
public void setStartYear(int year)
year
- The daylight savings starting year.public void setStartRule(int month, int dayOfWeekInMonth, int dayOfWeek, int time)
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.public void setStartRule(int month, int dayOfMonth, int time)
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.public void setStartRule(int month, int dayOfMonth, int dayOfWeek, int time, boolean after)
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.public void setEndRule(int month, int dayOfWeekInMonth, int dayOfWeek, int time)
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.public void setEndRule(int month, int dayOfMonth, int time)
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.public void setEndRule(int month, int dayOfMonth, int dayOfWeek, int time, boolean after)
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.public int getOffset(int era, int year, int month, int day, int dayOfWeek, int millis)
Calendar.get(ZONE_OFFSET) +
Calendar.get(DST_OFFSET)
instead.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 milliseconds in day in standard local time.int getOffset(int era, int year, int month, int day, int dayOfWeek, int millis, int monthLength)
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 milliseconds in day in standard local time.monthLength
- The length of the given month in days.private static int compareToRule(int month, int monthLen, int dayOfMonth, int dayOfWeek, int millis, int ruleMode, int ruleMonth, int ruleDayOfWeek, int ruleDay, int ruleMillis)
public int getRawOffset()
public void setRawOffset(int offsetMillis)
public void setDSTSavings(int millisSavedDuringDST)
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).public int getDSTSavings()
public boolean useDaylightTime()
public boolean inDaylightTime(Date date)
public Object clone()
public int hashCode()
public boolean equals(Object obj)
obj
- The SimpleTimeZone object to be compared with.public boolean hasSameRules(TimeZone other)
other
- the TimeZone object to be compared withpublic String toString()
private void decodeRules()
private void decodeStartRule()
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 careThe 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.
private void decodeEndRule()
decodeStartRule
private void makeRulesCompatible()
private byte[] packRules()
private void unpackRules(byte[] rules)
private void writeObject(ObjectOutputStream stream) throws IOException
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |