Constructor: |
public SimpleTimeZone(int rawOffset,
String ID) {
this.rawOffset = rawOffset;
setID (ID);
dstSavings = millisPerHour; // In case user sets rules later
}
Constructs a SimpleTimeZone with the given base time zone offset from GMT
and time zone ID with no daylight saving time schedule. Parameters:
rawOffset - The base time zone offset in milliseconds to GMT.
ID - The time zone name that is given to this instance.
|
public SimpleTimeZone(int rawOffset,
String ID,
int startMonth,
int startDay,
int startDayOfWeek,
int startTime,
int endMonth,
int endDay,
int endDayOfWeek,
int endTime) {
this(rawOffset, ID,
startMonth, startDay, startDayOfWeek, startTime, WALL_TIME,
endMonth, endDay, endDayOfWeek, endTime, WALL_TIME,
millisPerHour);
}
Constructs a SimpleTimeZone with the given base time zone offset from
GMT, time zone ID, and rules for starting and ending the daylight
time.
Both startTime and endTime are specified to be
represented in the wall clock time. The amount of daylight saving is
assumed to be 3600000 milliseconds (i.e., one hour). This constructor is
equivalent to:
SimpleTimeZone(rawOffset,
ID,
startMonth,
startDay,
startDayOfWeek,
startTime,
SimpleTimeZone.#WALL_TIME ,
endMonth,
endDay,
endDayOfWeek,
endTime,
SimpleTimeZone.#WALL_TIME ,
3600000)
Parameters:
rawOffset - The given base time zone offset from GMT.
ID - The time zone ID which is given to this object.
startMonth - The daylight saving time starting month. Month is
a MONTH field value (0-based. e.g., 0
for January).
startDay - The day of the month on which the daylight saving time starts.
See the class description for the special cases of this parameter.
startDayOfWeek - The daylight saving time starting day-of-week.
See the class description for the special cases of this parameter.
startTime - The daylight saving time starting time in local wall clock
time (in milliseconds within the day), which is local
standard time in this case.
endMonth - The daylight saving time ending month. Month is
a MONTH field
value (0-based. e.g., 9 for October).
endDay - The day of the month on which the daylight saving time ends.
See the class description for the special cases of this parameter.
endDayOfWeek - The daylight saving time ending day-of-week.
See the class description for the special cases of this parameter.
endTime - The daylight saving ending time in local wall clock time,
(in milliseconds within the day) which is local daylight
time in this case.
Throws:
IllegalArgumentException - if the month, day, dayOfWeek, or time
parameters are out of range for the start or end rule
- exception:
IllegalArgumentException - if the month, day, dayOfWeek, or time
parameters are out of range for the start or end rule
|
public SimpleTimeZone(int rawOffset,
String ID,
int startMonth,
int startDay,
int startDayOfWeek,
int startTime,
int endMonth,
int endDay,
int endDayOfWeek,
int endTime,
int dstSavings) {
this(rawOffset, ID,
startMonth, startDay, startDayOfWeek, startTime, WALL_TIME,
endMonth, endDay, endDayOfWeek, endTime, WALL_TIME,
dstSavings);
}
Constructs a SimpleTimeZone with the given base time zone offset from
GMT, time zone ID, and rules for starting and ending the daylight
time.
Both startTime and endTime are assumed to be
represented in the wall clock time. This constructor is equivalent to:
SimpleTimeZone(rawOffset,
ID,
startMonth,
startDay,
startDayOfWeek,
startTime,
SimpleTimeZone.#WALL_TIME ,
endMonth,
endDay,
endDayOfWeek,
endTime,
SimpleTimeZone.#WALL_TIME ,
dstSavings)
Parameters:
rawOffset - The given base time zone offset from GMT.
ID - The time zone ID which is given to this object.
startMonth - The daylight saving time starting month. Month is
a MONTH field
value (0-based. e.g., 0 for January).
startDay - The day of the month on which the daylight saving time starts.
See the class description for the special cases of this parameter.
startDayOfWeek - The daylight saving time starting day-of-week.
See the class description for the special cases of this parameter.
startTime - The daylight saving time starting time in local wall clock
time, which is local standard time in this case.
endMonth - The daylight saving time ending month. Month is
a MONTH field
value (0-based. e.g., 9 for October).
endDay - The day of the month on which the daylight saving time ends.
See the class description for the special cases of this parameter.
endDayOfWeek - The daylight saving time ending day-of-week.
See the class description for the special cases of this parameter.
endTime - The daylight saving ending time in local wall clock time,
which is local daylight time in this case.
dstSavings - The amount of time in milliseconds saved during
daylight saving time.
Throws:
IllegalArgumentException - if the month, day, dayOfWeek, or time
parameters are out of range for the start or end rule
- exception:
IllegalArgumentException - if the month, day, dayOfWeek, or time
parameters are out of range for the start or end rule
- since:
1.2 -
|
public SimpleTimeZone(int rawOffset,
String ID,
int startMonth,
int startDay,
int startDayOfWeek,
int startTime,
int startTimeMode,
int endMonth,
int endDay,
int endDayOfWeek,
int endTime,
int endTimeMode,
int dstSavings) {
setID(ID);
this.rawOffset = rawOffset;
this.startMonth = startMonth;
this.startDay = startDay;
this.startDayOfWeek = startDayOfWeek;
this.startTime = startTime;
this.startTimeMode = startTimeMode;
this.endMonth = endMonth;
this.endDay = endDay;
this.endDayOfWeek = endDayOfWeek;
this.endTime = endTime;
this.endTimeMode = endTimeMode;
this.dstSavings = dstSavings;
// this.useDaylight is set by decodeRules
decodeRules();
if (dstSavings < = 0) {
throw new IllegalArgumentException("Illegal daylight saving value: " + dstSavings);
}
}
Constructs a SimpleTimeZone with the given base time zone offset from
GMT, time zone ID, and rules for starting and ending the daylight
time.
This constructor takes the full set of the start and end rules
parameters, including modes of startTime and
endTime . The mode specifies either wall
time or standard time or UTC
time . Parameters:
rawOffset - The given base time zone offset from GMT.
ID - The time zone ID which is given to this object.
startMonth - The daylight saving time starting month. Month is
a MONTH field
value (0-based. e.g., 0 for January).
startDay - The day of the month on which the daylight saving time starts.
See the class description for the special cases of this parameter.
startDayOfWeek - The daylight saving time starting day-of-week.
See the class description for the special cases of this parameter.
startTime - The daylight saving time starting time in the time mode
specified by startTimeMode .
startTimeMode - The mode of the start time specified by startTime.
endMonth - The daylight saving time ending month. Month is
a MONTH field
value (0-based. e.g., 9 for October).
endDay - The day of the month on which the daylight saving time ends.
See the class description for the special cases of this parameter.
endDayOfWeek - The daylight saving time ending day-of-week.
See the class description for the special cases of this parameter.
endTime - The daylight saving ending time in time time mode
specified by endTimeMode .
endTimeMode - The mode of the end time specified by endTime
dstSavings - The amount of time in milliseconds saved during
daylight saving time.
Throws:
IllegalArgumentException - if the month, day, dayOfWeek, time more, or
time parameters are out of range for the start or end rule, or if a time mode
value is invalid.
Also see:
- WALL_TIME
- STANDARD_TIME
- UTC_TIME
- exception:
IllegalArgumentException - if the month, day, dayOfWeek, time more, or
time parameters are out of range for the start or end rule, or if a time mode
value is invalid.
- since:
1.4 -
|
Method from java.util.SimpleTimeZone Detail: |
public Object clone() {
return super.clone();
}
Returns a clone of this SimpleTimeZone instance. |
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof SimpleTimeZone)) {
return false;
}
SimpleTimeZone that = (SimpleTimeZone) obj;
return getID().equals(that.getID()) &&
hasSameRules(that);
}
Compares the equality of two SimpleTimeZone objects. |
public int getDSTSavings() {
return useDaylight ? dstSavings : 0;
}
Returns the amount of time in milliseconds that the clock is
advanced during daylight saving time. |
public int getOffset(long date) {
return getOffsets(date, null);
}
Returns the offset of this time zone from UTC at the given
time. If daylight saving time is in effect at the given time,
the offset value is adjusted with the amount of daylight
saving. |
public int getOffset(int era,
int year,
int month,
int day,
int dayOfWeek,
int millis) {
if (era != GregorianCalendar.AD && era != GregorianCalendar.BC) {
throw new IllegalArgumentException("Illegal era " + era);
}
int y = year;
if (era == GregorianCalendar.BC) {
// adjust y with the GregorianCalendar-style year numbering.
y = 1 - y;
}
// If the year isn't representable with the 64-bit long
// integer in milliseconds, convert the year to an
// equivalent year. This is required to pass some JCK test cases
// which are actually useless though because the specified years
// can't be supported by the Java time system.
if (y >= 292278994) {
y = 2800 + y % 2800;
} else if (y < = -292269054) {
// y %= 28 also produces an equivalent year, but positive
// year numbers would be convenient to use the UNIX cal
// command.
y = (int) CalendarUtils.mod((long) y, 28);
}
// convert year to its 1-based month value
int m = month + 1;
// First, calculate time as a Gregorian date.
BaseCalendar cal = gcal;
BaseCalendar.Date cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE);
cdate.setDate(y, m, day);
long time = cal.getTime(cdate); // normalize cdate
time += millis - rawOffset; // UTC time
// If the time value represents a time before the default
// Gregorian cutover, recalculate time using the Julian
// calendar system. For the Julian calendar system, the
// normalized year numbering is ..., -2 (BCE 2), -1 (BCE 1),
// 1, 2 ... which is different from the GregorianCalendar
// style year numbering (..., -1, 0 (BCE 1), 1, 2, ...).
if (time < GregorianCalendar.DEFAULT_GREGORIAN_CUTOVER) {
cal = (BaseCalendar) CalendarSystem.forName("julian");
cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE);
cdate.setNormalizedDate(y, m, day);
time = cal.getTime(cdate) + millis - rawOffset;
}
if ((cdate.getNormalizedYear() != y)
|| (cdate.getMonth() != m)
|| (cdate.getDayOfMonth() != day)
// The validation should be cdate.getDayOfWeek() ==
// dayOfWeek. However, we don't check dayOfWeek for
// compatibility.
|| (dayOfWeek < Calendar.SUNDAY || dayOfWeek > Calendar.SATURDAY)
|| (millis < 0 || millis >= (24*60*60*1000))) {
throw new IllegalArgumentException();
}
if (!useDaylight || year < startYear || era != GregorianCalendar.CE) {
return rawOffset;
}
return getOffset(cal, cdate, y, time);
}
Returns the difference in milliseconds between local time and
UTC, taking into account both the raw offset and the effect of
daylight saving, for the specified date and time. This method
assumes that the start and end month are distinct. It also
uses a default GregorianCalendar object as its
underlying calendar, such as for determining leap years. Do
not use the result of this method with a calendar other than a
default GregorianCalendar .
Note: In general, clients should use
Calendar.get(ZONE_OFFSET) + Calendar.get(DST_OFFSET)
instead of calling this method. |
int getOffsets(long date,
int[] offsets) {
int offset = rawOffset;
computeOffset:
if (useDaylight) {
synchronized (this) {
if (cacheStart != 0) {
if (date >= cacheStart && date < cacheEnd) {
offset += dstSavings;
break computeOffset;
}
}
}
BaseCalendar cal = date >= GregorianCalendar.DEFAULT_GREGORIAN_CUTOVER ?
gcal : (BaseCalendar) CalendarSystem.forName("julian");
BaseCalendar.Date cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE);
// Get the year in local time
cal.getCalendarDate(date + rawOffset, cdate);
int year = cdate.getNormalizedYear();
if (year >= startYear) {
// Clear time elements for the transition calculations
cdate.setTimeOfDay(0, 0, 0, 0);
offset = getOffset(cal, cdate, year, date);
}
}
if (offsets != null) {
offsets[0] = rawOffset;
offsets[1] = offset - rawOffset;
}
return offset;
}
|
public int getRawOffset() {
// The given date will be taken into account while
// we have the historical time zone data in place.
return rawOffset;
}
Gets the GMT offset for this time zone. |
public boolean hasSameRules(TimeZone other) {
if (this == other) {
return true;
}
if (!(other instanceof SimpleTimeZone)) {
return false;
}
SimpleTimeZone that = (SimpleTimeZone) other;
return rawOffset == that.rawOffset &&
useDaylight == that.useDaylight &&
(!useDaylight
// Only check rules if using DST
|| (dstSavings == that.dstSavings &&
startMode == that.startMode &&
startMonth == that.startMonth &&
startDay == that.startDay &&
startDayOfWeek == that.startDayOfWeek &&
startTime == that.startTime &&
startTimeMode == that.startTimeMode &&
endMode == that.endMode &&
endMonth == that.endMonth &&
endDay == that.endDay &&
endDayOfWeek == that.endDayOfWeek &&
endTime == that.endTime &&
endTimeMode == that.endTimeMode &&
startYear == that.startYear));
}
Returns true if this zone has the same rules and offset as another zone. |
public synchronized int hashCode() {
return startMonth ^ startDay ^ startDayOfWeek ^ startTime ^
endMonth ^ endDay ^ endDayOfWeek ^ endTime ^ rawOffset;
}
Generates the hash code for the SimpleDateFormat object. |
public boolean inDaylightTime(Date date) {
return (getOffset(date.getTime()) != rawOffset);
}
Queries if the given date is in daylight saving time. |
public boolean observesDaylightTime() {
return useDaylightTime();
}
Returns {@code true} if this {@code SimpleTimeZone} observes
Daylight Saving Time. This method is equivalent to #useDaylightTime() . |
public void setDSTSavings(int millisSavedDuringDST) {
if (millisSavedDuringDST < = 0) {
throw new IllegalArgumentException("Illegal daylight saving value: "
+ millisSavedDuringDST);
}
dstSavings = millisSavedDuringDST;
}
Sets the amount of time in milliseconds that the clock is advanced
during daylight saving time. |
public void setEndRule(int endMonth,
int endDay,
int endTime) {
setEndRule(endMonth, endDay, 0, endTime);
}
Sets the daylight saving time end rule to a fixed date within a month.
This method is equivalent to:
setEndRule(endMonth, endDay, 0, endTime)
|
public void setEndRule(int endMonth,
int endDay,
int endDayOfWeek,
int endTime) {
this.endMonth = endMonth;
this.endDay = endDay;
this.endDayOfWeek = endDayOfWeek;
this.endTime = endTime;
this.endTimeMode = WALL_TIME;
decodeEndRule();
invalidateCache();
}
Sets the daylight saving time end rule. For example, if daylight saving time
ends on the last Sunday in October at 2 am in wall clock time,
you can set the end rule by calling:
setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2*60*60*1000); |
public void setEndRule(int endMonth,
int endDay,
int endDayOfWeek,
int endTime,
boolean after) {
if (after) {
setEndRule(endMonth, endDay, -endDayOfWeek, endTime);
} else {
setEndRule(endMonth, -endDay, -endDayOfWeek, endTime);
}
}
Sets the daylight saving time end rule to a weekday before or after the given date within
a month, e.g., the first Monday on or after the 8th. |
public void setRawOffset(int offsetMillis) {
this.rawOffset = offsetMillis;
}
Sets the base time zone offset to GMT.
This is the offset to add to UTC to get local time. |
public void setStartRule(int startMonth,
int startDay,
int startTime) {
setStartRule(startMonth, startDay, 0, startTime);
}
Sets the daylight saving time start rule to a fixed date within a month.
This method is equivalent to:
setStartRule(startMonth, startDay, 0, startTime)
|
public void setStartRule(int startMonth,
int startDay,
int startDayOfWeek,
int startTime) {
this.startMonth = startMonth;
this.startDay = startDay;
this.startDayOfWeek = startDayOfWeek;
this.startTime = startTime;
startTimeMode = WALL_TIME;
decodeStartRule();
invalidateCache();
}
Sets the daylight saving time start rule. For example, if daylight saving
time starts on the first Sunday in April at 2 am in local wall clock
time, you can set the start rule by calling:
setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2*60*60*1000);
|
public void setStartRule(int startMonth,
int startDay,
int startDayOfWeek,
int startTime,
boolean after) {
// TODO: this method doesn't check the initial values of dayOfMonth or dayOfWeek.
if (after) {
setStartRule(startMonth, startDay, -startDayOfWeek, startTime);
} else {
setStartRule(startMonth, -startDay, -startDayOfWeek, startTime);
}
}
Sets the daylight saving time start rule to a weekday before or after the given date within
a month, e.g., the first Monday on or after the 8th. |
public void setStartYear(int year) {
startYear = year;
invalidateCache();
}
Sets the daylight saving time starting year. |
public String toString() {
return getClass().getName() +
"[id=" + getID() +
",offset=" + rawOffset +
",dstSavings=" + dstSavings +
",useDaylight=" + useDaylight +
",startYear=" + startYear +
",startMode=" + startMode +
",startMonth=" + startMonth +
",startDay=" + startDay +
",startDayOfWeek=" + startDayOfWeek +
",startTime=" + startTime +
",startTimeMode=" + startTimeMode +
",endMode=" + endMode +
",endMonth=" + endMonth +
",endDay=" + endDay +
",endDayOfWeek=" + endDayOfWeek +
",endTime=" + endTime +
",endTimeMode=" + endTimeMode + ']';
}
Returns a string representation of this time zone. |
public boolean useDaylightTime() {
return useDaylight;
}
Queries if this time zone uses daylight saving time. |