1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.lum.common.client.widgets; |
17 | |
|
18 | |
import java.util.Date; |
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
public abstract class Calendar |
31 | |
{ |
32 | |
public static final int AM = 0; |
33 | |
public static final int AM_PM = 9; |
34 | |
public static final int PM = 1; |
35 | |
|
36 | |
public static final int JANUARY = 0; |
37 | |
public static final int FEBRUARY = 1; |
38 | |
public static final int MARCH = 2; |
39 | |
public static final int APRIL = 3; |
40 | |
public static final int MAY = 4; |
41 | |
public static final int JUNE = 5; |
42 | |
public static final int JULY = 6; |
43 | |
public static final int AUGUST = 7; |
44 | |
public static final int SEPTEMBER = 8; |
45 | |
public static final int OCTOBER = 9; |
46 | |
public static final int NOVEMBER = 10; |
47 | |
public static final int DECEMBER = 11; |
48 | |
public static final int UNDECIMBER = 12; |
49 | |
|
50 | |
public static final int SUNDAY = 1; |
51 | |
public static final int MONDAY = 2; |
52 | |
public static final int TUESDAY = 3; |
53 | |
public static final int WEDNESDAY = 4; |
54 | |
public static final int THURSDAY = 5; |
55 | |
public static final int FRIDAY = 6; |
56 | |
public static final int SATURDAY = 7; |
57 | |
|
58 | |
|
59 | |
public static final int ERA = 0; |
60 | |
public static final int YEAR = 1; |
61 | |
public static final int MONTH = 2; |
62 | |
public static final int WEEK_OF_YEAR = 3; |
63 | |
public static final int WEEK_OF_MONTH = 4; |
64 | |
public static final int DATE = 5; |
65 | |
public static final int DAY_OF_MONTH = DATE; |
66 | |
public static final int DAY_OF_YEAR = 6; |
67 | |
public static final int DAY_OF_WEEK = 7; |
68 | |
public static final int DAY_OF_WEEK_IN_MONTH = 8; |
69 | |
public static final int HOUR = 10; |
70 | |
public static final int HOUR_OF_DAY = 11; |
71 | |
public static final int MINUTE = 12; |
72 | |
public static final int SECOND = 13; |
73 | |
public static final int MILLISECOND = 14; |
74 | |
public static final int ZONE_OFFSET = 15; |
75 | |
public static final int DST_OFFSET = 16; |
76 | |
public static final int FIELD_COUNT = 17; |
77 | |
|
78 | |
|
79 | |
|
80 | 0 | protected Date date = null; |
81 | 0 | protected int second = -1; |
82 | 0 | protected int minute = -1; |
83 | 0 | protected int hour = -1; |
84 | 0 | protected int dayOfMonth = -1; |
85 | 0 | protected int month = -1; |
86 | 0 | protected int year = -1; |
87 | 0 | protected int amPm = -1; |
88 | |
|
89 | 0 | protected int firstWeekDayOfWeek = Calendar.SUNDAY; |
90 | |
|
91 | 0 | protected Calendar() { |
92 | 0 | setTime(new Date()); |
93 | 0 | } |
94 | |
|
95 | |
|
96 | |
public void setTime(Date date) { |
97 | 0 | this.date = date; |
98 | 0 | computeFields(); |
99 | 0 | } |
100 | |
public void setTime(Calendar cal) { |
101 | 0 | this.date = cal.getTime(); |
102 | 0 | computeFields(); |
103 | 0 | } |
104 | |
|
105 | |
public void setTimeInMillis(long milliSeconds) { |
106 | 0 | this.date.setTime(milliSeconds); |
107 | 0 | computeFields(); |
108 | 0 | } |
109 | |
|
110 | |
public void set(int year, int month, int dayOfMonth) { |
111 | 0 | this.year = year; |
112 | 0 | this.month = month; |
113 | 0 | this.dayOfMonth = dayOfMonth; |
114 | 0 | computeTime(); |
115 | 0 | } |
116 | |
|
117 | |
public void set(int year, int month, int dayOfMonth, int hour) { |
118 | 0 | this.year = year; |
119 | 0 | this.month = month; |
120 | 0 | this.dayOfMonth = dayOfMonth; |
121 | 0 | this.hour = hour; |
122 | 0 | computeTime(); |
123 | 0 | } |
124 | |
|
125 | |
public void set(int year, int month, int dayOfMonth, int hour, int minute) { |
126 | 0 | this.year = year; |
127 | 0 | this.month = month; |
128 | 0 | this.dayOfMonth = dayOfMonth; |
129 | 0 | this.hour = hour; |
130 | 0 | this.minute = minute; |
131 | 0 | computeTime(); |
132 | 0 | } |
133 | |
|
134 | |
public void set(int year, int month, int dayOfMonth, int hour, int minute, int second) { |
135 | 0 | this.year = year; |
136 | 0 | this.month = month; |
137 | 0 | this.dayOfMonth = dayOfMonth; |
138 | 0 | this.hour = hour; |
139 | 0 | this.minute = minute; |
140 | 0 | this.second = second; |
141 | 0 | computeTime(); |
142 | 0 | } |
143 | |
|
144 | |
public void set(int fieldCode, String value) { |
145 | 0 | set(fieldCode, Integer.parseInt(value)); |
146 | 0 | } |
147 | |
public abstract void set(int fieldCode, int value); |
148 | |
|
149 | |
|
150 | |
public void setFirstWeekDayOfWeek(int firstWeekDayOfWeek) { |
151 | 0 | this.firstWeekDayOfWeek = firstWeekDayOfWeek; |
152 | 0 | } |
153 | |
|
154 | |
|
155 | |
|
156 | |
public Date getTime() { |
157 | 0 | return this.date; |
158 | |
} |
159 | |
|
160 | |
public long getTimeInMillis() { |
161 | 0 | return this.date.getTime(); |
162 | |
} |
163 | |
|
164 | |
|
165 | |
|
166 | |
public int get(int fieldCode) { |
167 | 0 | switch (fieldCode) { |
168 | |
case Calendar.SECOND: |
169 | 0 | return this.second; |
170 | |
case Calendar.MINUTE: |
171 | 0 | return this.minute; |
172 | |
case Calendar.HOUR: |
173 | 0 | return this.hour; |
174 | |
case Calendar.HOUR_OF_DAY: |
175 | 0 | if (this.amPm == Calendar.PM) |
176 | 0 | return this.hour + 12; |
177 | 0 | return this.hour; |
178 | |
case Calendar.DATE: |
179 | 0 | return this.dayOfMonth; |
180 | |
case Calendar.MONTH: |
181 | 0 | return this.month; |
182 | |
case Calendar.YEAR: |
183 | 0 | return this.year; |
184 | |
case Calendar.AM_PM: |
185 | 0 | return this.amPm; |
186 | |
default: |
187 | 0 | return -1; |
188 | |
} |
189 | |
} |
190 | |
|
191 | |
public int getFirstWeekDayOfWeek() { |
192 | 0 | return this.firstWeekDayOfWeek; |
193 | |
} |
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
public boolean before(Date when) { |
199 | 0 | return this.date.before(when); |
200 | |
} |
201 | |
public boolean before(Calendar when) { |
202 | 0 | return this.date.before(when.getTime()); |
203 | |
} |
204 | |
public boolean after(Date when) { |
205 | 0 | return this.date.after(when); |
206 | |
} |
207 | |
public boolean after(Calendar when) { |
208 | 0 | return this.date.after(when.getTime()); |
209 | |
} |
210 | |
public boolean equals(Date obj) { |
211 | 0 | return this.date.equals(obj); |
212 | |
} |
213 | |
public boolean equals(Calendar obj) { |
214 | 0 | return this.date.equals(obj.getTime()); |
215 | |
} |
216 | |
|
217 | |
public boolean isSet(int fieldCode) { |
218 | 0 | return true; |
219 | |
} |
220 | |
|
221 | |
|
222 | |
|
223 | |
public void roll(int fieldCode, boolean up) { |
224 | 0 | if (up) |
225 | 0 | roll(fieldCode, 1); |
226 | |
else |
227 | 0 | roll(fieldCode, -1); |
228 | 0 | } |
229 | |
|
230 | |
|
231 | |
protected void complete() { |
232 | 0 | computeFields(); |
233 | 0 | } |
234 | |
|
235 | |
|
236 | |
public int hashCode() { |
237 | 0 | return this.date.hashCode(); |
238 | |
} |
239 | |
|
240 | |
public String toString() { |
241 | 0 | return this.date.toString(); |
242 | |
} |
243 | |
|
244 | |
|
245 | |
|
246 | |
|
247 | |
protected abstract void computeFields(); |
248 | |
|
249 | |
|
250 | |
protected abstract void computeTime(); |
251 | |
|
252 | |
|
253 | |
|
254 | |
public abstract int getMinimum(int fieldCode); |
255 | |
|
256 | |
public abstract int getActualMinimum(int fieldCode); |
257 | |
|
258 | |
public abstract int getGreatestMinimum(int fieldCode); |
259 | |
|
260 | |
|
261 | |
public abstract int getMaximum(int fieldCode); |
262 | |
|
263 | |
public abstract int getActualMaximum(int fieldCode); |
264 | |
|
265 | |
public abstract int getLeastMaximum(int fieldCode); |
266 | |
|
267 | |
|
268 | |
|
269 | |
public abstract void add(int fieldCode, int amount); |
270 | |
|
271 | |
|
272 | |
public abstract void roll(int fieldCode, int amount); |
273 | |
|
274 | |
|
275 | |
} |