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      protected Date date                 = null;
81      protected int second                = -1;
82      protected int minute                = -1;
83      protected int hour                  = -1;
84      protected int dayOfMonth            = -1;
85      protected int month                 = -1;
86      protected int year                  = -1;
87      protected int amPm                  = -1;
88  
89      protected int firstWeekDayOfWeek    = Calendar.SUNDAY;
90  
91      protected Calendar() {
92          setTime(new Date());
93      }
94  
95      
96      public void setTime(Date date) {
97          this.date               = date;
98          computeFields();
99      }
100     public void setTime(Calendar cal) {
101         this.date               = cal.getTime();
102         computeFields();
103     }
104     
105     public void setTimeInMillis(long milliSeconds) {
106         this.date.setTime(milliSeconds);
107         computeFields();
108     }
109     
110     public void set(int year, int month, int dayOfMonth) {
111         this.year               = year;
112         this.month              = month;
113         this.dayOfMonth         = dayOfMonth;
114         computeTime();
115     }
116     
117     public void set(int year, int month, int dayOfMonth, int hour) {
118         this.year               = year;
119         this.month              = month;
120         this.dayOfMonth         = dayOfMonth;
121         this.hour               = hour;
122         computeTime();
123     }
124     
125     public void set(int year, int month, int dayOfMonth, int hour, int minute) {
126         this.year               = year;
127         this.month              = month;
128         this.dayOfMonth         = dayOfMonth;
129         this.hour               = hour;
130         this.minute             = minute;
131         computeTime();
132     }
133     
134     public void set(int year, int month, int dayOfMonth, int hour, int minute, int second) {
135         this.year               = year;
136         this.month              = month;
137         this.dayOfMonth         = dayOfMonth;
138         this.hour               = hour;
139         this.minute             = minute;
140         this.second             = second;
141         computeTime();
142     }
143     
144     public void set(int fieldCode, String value) {
145         set(fieldCode, Integer.parseInt(value));
146     }
147     public abstract void set(int fieldCode, int value);
148 
149     
150     public void setFirstWeekDayOfWeek(int firstWeekDayOfWeek) {
151         this.firstWeekDayOfWeek = firstWeekDayOfWeek;
152     }
153 
154 
155     
156     public Date getTime() {
157         return this.date;
158     }
159     
160     public long getTimeInMillis() {
161         return this.date.getTime();
162     }
163 
164 
165     
166     public int get(int fieldCode) {
167         switch (fieldCode) {
168         case Calendar.SECOND:
169             return this.second;
170         case Calendar.MINUTE:
171             return this.minute;
172         case Calendar.HOUR:
173             return this.hour;
174         case Calendar.HOUR_OF_DAY:
175             if (this.amPm == Calendar.PM)
176                 return this.hour + 12;
177             return this.hour;
178         case Calendar.DATE:
179             return this.dayOfMonth;
180         case Calendar.MONTH:
181             return this.month;
182         case Calendar.YEAR:
183             return this.year;
184         case Calendar.AM_PM:
185             return this.amPm;
186         default:
187             return -1;
188         }
189     }
190     
191     public int getFirstWeekDayOfWeek() {
192         return this.firstWeekDayOfWeek;
193     }
194 
195 
196 
197     
198     public boolean before(Date when) {
199         return this.date.before(when);
200     }
201     public boolean before(Calendar when) {
202         return this.date.before(when.getTime());
203     }
204     public boolean after(Date when) {
205         return this.date.after(when);
206     }
207     public boolean after(Calendar when) {
208         return this.date.after(when.getTime());
209     }
210     public boolean equals(Date obj) {
211         return this.date.equals(obj);
212     }
213     public boolean equals(Calendar obj) {
214         return this.date.equals(obj.getTime());
215     }
216     
217     public boolean isSet(int fieldCode) {
218         return true;
219     }
220 
221 
222     
223     public void roll(int fieldCode, boolean up) {
224         if (up)
225             roll(fieldCode, 1);
226         else
227             roll(fieldCode, -1);
228     }
229 
230     
231     protected  void complete() {
232         computeFields();
233     }
234 
235     
236     public int hashCode() {
237         return this.date.hashCode();
238     }
239     
240     public String toString() {
241         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 }