1 /* Copyright (C) 1998, 1999 Cygnus Solutions
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
12 * @author Per Bothner <bothner@cygnus.com>
13 * @date October 24, 1998.
16 /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3.
17 * Status: Does not know how to figure out if daylight savings time
18 * is in effect; hence only correct for zones without DST.
19 * No known spec for hashCode.
22 public class SimpleTimeZone
extends TimeZone
24 // The fields are as specified in Sun's "Serialized Form"
25 // in the JDK 1.2 beta 4 API specification.
27 int dstSavings
= 60 * 60 * 1000;
31 // int serialVersionOnStream;
35 int startMode
; /// Seems to be JDK 1.2 only.
47 int endMode
; // Seems to be JDK 1.2 only.
53 // byte[] monthLength;
57 public SimpleTimeZone (int rawOffset
, String ID
)
60 this.rawOffset
= rawOffset
;
63 public SimpleTimeZone (int rawOffset
, String ID
,
64 int startMonth
, int startDay
,
65 int startDayOfWeek
, int startTime
,
66 int endMonth
, int endDay
,
67 int endDayOfWeek
, int endTime
)
70 setStartRule (startMonth
, startDay
, startDayOfWeek
, startTime
);
71 setEndRule (endMonth
, endDay
, endDayOfWeek
, endTime
);
74 public int getRawOffset() { return rawOffset
; }
75 public void setRawOffset (int offsetMillis
) { rawOffset
= offsetMillis
; }
77 public int getOffset (int era
, int year
, int month
, int day
,
78 int dayOfWeek
, int millis
)
80 int offset
= getRawOffset();
84 && (year
< startYear
|| era
== GregorianCalendar
.BC
))
86 boolean midYearSummer
= startMonth
< endMonth
;
87 if (midYearSummer ?
(month
< startMonth
|| month
> endMonth
)
88 : (month
< startMonth
&& month
> endMonth
))
89 return offset
; // Definitely not DST.
90 if (midYearSummer ?
(month
> startMonth
&& month
< endMonth
)
91 : (month
> startMonth
|| month
< endMonth
))
92 return offset
+ dstSavings
; // Definitely DST.
93 // Now it gets more complicated. Bail for now.
94 throw new Error("not implemented - SimpleTimeZone.getOffset");
99 public boolean useDaylightTime() { return useDaylight
; }
101 public boolean inDaylightTime(Date date
)
105 throw new Error("not implemented - SimpleTimeZone.inDaylightTime");
108 public int getDSTSavings () { return dstSavings
; }
110 public void setDSTSavings (int millisSavedDuringDST
)
111 { dstSavings
= millisSavedDuringDST
; }
113 public void setStartRule (int month
, int dayOfWeekInMonth
,
114 int dayOfWeek
, int time
)
116 this.startMonth
= month
;
117 this.startDay
= dayOfWeekInMonth
;
118 this.startDayOfWeek
= dayOfWeek
;
119 this.startTime
= time
;
120 this.useDaylight
= true;
123 public void setEndRule (int month
, int dayOfWeekInMonth
,
124 int dayOfWeek
, int time
)
126 this.endMonth
= month
;
127 this.endDay
= dayOfWeekInMonth
;
128 this.endDayOfWeek
= dayOfWeek
;
130 this.useDaylight
= true;
133 public void setStartYear (int year
)
135 this.startYear
= startYear
;
138 public boolean hasSameRules (TimeZone other
)
142 if (! (other
instanceof SimpleTimeZone
))
144 SimpleTimeZone o
= (SimpleTimeZone
) other
;
145 if (rawOffset
!= o
.rawOffset
)
147 if (useDaylight
!= o
.useDaylight
)
151 return startDay
== o
.startDay
152 && startDayOfWeek
== o
.startDayOfWeek
153 && startMonth
== o
.startMonth
154 && startTime
== o
.startTime
155 && endDay
== o
.endDay
156 && endDayOfWeek
== o
.endDayOfWeek
157 && endMonth
== o
.endMonth
158 && endTime
== o
.endTime
159 && startYear
== o
.startYear
160 && startMode
== o
.startMode
161 && endMode
== o
.endMode
;
164 public boolean equals (Object obj
)
166 if (! (obj
instanceof SimpleTimeZone
))
168 SimpleTimeZone other
= (SimpleTimeZone
) obj
;
169 return getID() == other
.getID() && hasSameRules(other
);
172 public int hashCode ()
174 // FIXME - this does not folow any spec (since none is public)!
175 int hash
= rawOffset
;
177 hash
+= dstSavings
+ startYear
+ startMode
+ endMode
178 + startDay
+ startDayOfWeek
+ startMonth
+ startTime
179 + endDay
+ endDayOfWeek
+ endMonth
+ endTime
;