/*
-* Copyright (C) 1996-2010, International Business Machines
+* Copyright (C) 1996-2013, International Business Machines
* Corporation and others. All Rights Reserved.
*/
* @stable ICU 2.0
*/
public SimpleTimeZone(int rawOffset, String ID) {
+ super(ID);
construct(rawOffset, 0, 0, 0,
0, WALL_TIME,
0, 0, 0,
0, WALL_TIME,
Grego.MILLIS_PER_HOUR);
- super.setID(ID);
}
/**
public SimpleTimeZone(int rawOffset, String ID,
int startMonth, int startDay, int startDayOfWeek, int startTime,
int endMonth, int endDay, int endDayOfWeek, int endTime) {
+ super(ID);
construct(rawOffset,
startMonth, startDay, startDayOfWeek,
startTime, WALL_TIME,
endMonth, endDay, endDayOfWeek,
endTime, WALL_TIME,
Grego.MILLIS_PER_HOUR);
- super.setID(ID);
}
/**
int endMonth, int endDay,
int endDayOfWeek, int endTime,
int endTimeMode,int dstSavings){
+ super(ID);
construct(rawOffset,
startMonth, startDay, startDayOfWeek,
startTime, startTimeMode,
endMonth, endDay, endDayOfWeek,
endTime, endTimeMode,
dstSavings);
- super.setID(ID);
}
/**
int startMonth, int startDay, int startDayOfWeek, int startTime,
int endMonth, int endDay, int endDayOfWeek, int endTime,
int dstSavings) {
+ super(ID);
construct(rawOffset,
startMonth, startDay, startDayOfWeek,
startTime, WALL_TIME,
endMonth, endDay, endDayOfWeek,
endTime, WALL_TIME,
dstSavings);
- super.setID(ID);
}
/**
*
* @stable ICU 3.8
*/
+ @Override
public void setID(String ID) {
+ if (isFrozen()) {
+ throw new UnsupportedOperationException("Attempt to modify a frozen SimpleTimeZone instance.");
+ }
super.setID(ID);
-
transitionRulesInitialized = false;
}
* @param offsetMillis the raw offset of the time zone
* @stable ICU 2.0
*/
+ @Override
public void setRawOffset(int offsetMillis) {
- raw = offsetMillis;
+ if (isFrozen()) {
+ throw new UnsupportedOperationException("Attempt to modify a frozen SimpleTimeZone instance.");
+ }
+ raw = offsetMillis;
transitionRulesInitialized = false;
}
* @return the raw offset
* @stable ICU 2.0
*/
+ @Override
public int getRawOffset() {
return raw;
}
* @stable ICU 2.0
*/
public void setStartYear(int year) {
- //unwrapSTZ().setStartYear(year);
+ if (isFrozen()) {
+ throw new UnsupportedOperationException("Attempt to modify a frozen SimpleTimeZone instance.");
+ }
getSTZInfo().sy = year;
this.startYear = year;
-
transitionRulesInitialized = false;
}
*/
public void setStartRule(int month, int dayOfWeekInMonth, int dayOfWeek,
int time) {
+ if (isFrozen()) {
+ throw new UnsupportedOperationException("Attempt to modify a frozen SimpleTimeZone instance.");
+ }
+
getSTZInfo().setStart(month, dayOfWeekInMonth, dayOfWeek, time, -1, false);
setStartRule(month, dayOfWeekInMonth, dayOfWeek, time, WALL_TIME);
}
* description for an example.
*/
private void setStartRule(int month, int dayOfWeekInMonth, int dayOfWeek, int time, int mode) {
+ assert (!isFrozen());
+
startMonth = month;
startDay = dayOfWeekInMonth;
startDayOfWeek = dayOfWeek;
* @stable ICU 2.0
*/
public void setStartRule(int month, int dayOfMonth, int time) {
- // unwrapSTZ().setStartRule(month, dayOfMonth, time);
+ if (isFrozen()) {
+ throw new UnsupportedOperationException("Attempt to modify a frozen SimpleTimeZone instance.");
+ }
getSTZInfo().setStart(month, -1, -1, time, dayOfMonth, false);
setStartRule(month, dayOfMonth, 0, time, WALL_TIME);
* @stable ICU 2.0
*/
public void setStartRule(int month, int dayOfMonth, int dayOfWeek, int time, boolean after) {
+ if (isFrozen()) {
+ throw new UnsupportedOperationException("Attempt to modify a frozen SimpleTimeZone instance.");
+ }
+
getSTZInfo().setStart(month, -1, dayOfWeek, time, dayOfMonth, after);
setStartRule(month, after ? dayOfMonth : -dayOfMonth,
-dayOfWeek, time, WALL_TIME);
* @stable ICU 2.0
*/
public void setEndRule(int month, int dayOfWeekInMonth, int dayOfWeek, int time) {
+ if (isFrozen()) {
+ throw new UnsupportedOperationException("Attempt to modify a frozen SimpleTimeZone instance.");
+ }
+
getSTZInfo().setEnd(month, dayOfWeekInMonth, dayOfWeek, time, -1, false);
setEndRule(month, dayOfWeekInMonth, dayOfWeek, time, WALL_TIME);
}
* @stable ICU 2.0
*/
public void setEndRule(int month, int dayOfMonth, int time) {
+ if (isFrozen()) {
+ throw new UnsupportedOperationException("Attempt to modify a frozen SimpleTimeZone instance.");
+ }
+
getSTZInfo().setEnd(month, -1, -1, time, dayOfMonth, false);
setEndRule(month, dayOfMonth, WALL_TIME, time);
}
* @stable ICU 2.0
*/
public void setEndRule(int month, int dayOfMonth, int dayOfWeek, int time, boolean after) {
+ if (isFrozen()) {
+ throw new UnsupportedOperationException("Attempt to modify a frozen SimpleTimeZone instance.");
+ }
+
getSTZInfo().setEnd(month, -1, dayOfWeek, time, dayOfMonth, after);
setEndRule(month, dayOfMonth, dayOfWeek, time, WALL_TIME, after);
}
private void setEndRule(int month, int dayOfMonth, int dayOfWeek,
int time, int mode, boolean after){
+ assert (!isFrozen());
setEndRule(month, after ? dayOfMonth : -dayOfMonth, -dayOfWeek, time, mode);
}
* description for an example.
*/
private void setEndRule(int month, int dayOfWeekInMonth, int dayOfWeek, int time, int mode){
+ assert (!isFrozen());
+
endMonth = month;
endDay = dayOfWeekInMonth;
endDayOfWeek = dayOfWeek;
* @stable ICU 2.0
*/
public void setDSTSavings(int millisSavedDuringDST) {
+ if (isFrozen()) {
+ throw new UnsupportedOperationException("Attempt to modify a frozen SimpleTimeZone instance.");
+ }
+
if (millisSavedDuringDST <= 0) {
throw new IllegalArgumentException();
}
* are in effect. A positive number, typically one hour (3600000).
* @stable ICU 2.0
*/
+ @Override
public int getDSTSavings() {
return dst;
}
* @return a string representation of this object
* @stable ICU 3.6
*/
+ @Override
public String toString() {
return "SimpleTimeZone: " + getID();
}
* {@inheritDoc}
* @stable ICU 2.0
*/
+ @Override
public int getOffset(int era, int year, int month, int day,
int dayOfWeek, int millis)
{
Grego.monthLength(year, month), Grego.previousMonthLength(year, month));
}
- int getOffset(int era, int year, int month, int day,
+ private int getOffset(int era, int year, int month, int day,
int dayOfWeek, int millis,
int monthLength, int prevMonthLength ){
* Queries if this time zone uses Daylight Saving Time.
* @stable ICU 2.0
*/
+ @Override
public boolean useDaylightTime(){
return useDaylight;
}
+ /**
+ * {@inheritDoc}
+ * @stable ICU 49
+ */
+ public boolean observesDaylightTime() {
+ return useDaylight;
+ }
+
/**
* Overrides TimeZone
* Queries if the give date is in Daylight Saving Time.
* @stable ICU 2.0
*/
+ @Override
public boolean inDaylightTime(Date date){
GregorianCalendar gc = new GregorianCalendar(this);
gc.setTime(date);
* @return true if obj is a SimpleTimeZone equivalent to this
* @stable ICU 3.6
*/
+ @Override
public boolean equals(Object obj){
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
* Overrides hashCode.
* @stable ICU 3.6
*/
+ @Override
public int hashCode(){
int ret = super.hashCode()
+ raw ^ (raw >>> 8)
* Overrides clone.
* @stable ICU 3.6
*/
+ @Override
public Object clone() {
- return super.clone();
+ if (isFrozen()) {
+ return this;
+ }
+ return cloneAsThawed();
}
/**
* @return true if the given zone has the same rules and offset as this one
* @stable ICU 2.0
*/
+ @Override
public boolean hasSameRules(TimeZone othr) {
+ if (this == othr) {
+ return true;
+ }
if(!(othr instanceof SimpleTimeZone)){
- return false;
+ return false;
}
SimpleTimeZone other = (SimpleTimeZone)othr;
return other != null &&
* {@inheritDoc}
* @stable ICU 3.8
*/
+ @Override
public TimeZoneTransition getNextTransition(long base, boolean inclusive) {
if (!useDaylight) {
return null;
* {@inheritDoc}
* @stable ICU 3.8
*/
+ @Override
public TimeZoneTransition getPreviousTransition(long base, boolean inclusive) {
if (!useDaylight) {
return null;
* {@inheritDoc}
* @stable ICU 3.8
*/
+ @Override
public TimeZoneRule[] getTimeZoneRules() {
initTransitionRules();
}
transitionRulesInitialized = true;
}
+
+ // Freezable stuffs
+ private transient boolean isFrozen = false;
+
+ /**
+ * {@inheritDoc}
+ * @stable ICU 49
+ */
+ public boolean isFrozen() {
+ return isFrozen;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @stable ICU 49
+ */
+ public TimeZone freeze() {
+ isFrozen = true;
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @stable ICU 49
+ */
+ public TimeZone cloneAsThawed() {
+ SimpleTimeZone tz = (SimpleTimeZone)super.cloneAsThawed();
+ tz.isFrozen = false;
+ return tz;
+ }
}