|
@@ -9,87 +9,30 @@ |
9 |
9 |
|
import org.litesoft.core.typeutils.gregorian.*; |
10 |
10 |
|
|
11 |
11 |
|
/** |
12 |
|
- |
* A Simple date that acts as a proxy for a java.util.Date (burying the deprecated method use) providing |
|
12 |
+ |
* A date that acts as a sort of proxy for a java.util.Date (burying the deprecated method use) providing |
13 |
13 |
|
* varying levels of resolution based on the DateRes. |
14 |
14 |
|
* <p/> |
15 |
15 |
|
* Note: This class supports Gregorian dates only and has no concept of time or TimeZones. As such when working with |
16 |
16 |
|
* Java Util Date(s) (or it's descendants) the local (or "Wall") date is all that is considered! |
17 |
17 |
|
*/ |
18 |
|
- |
public final class CalendarYMD extends CalendarSupport<CalendarYMD> implements CalendarAccessorYMD, |
19 |
|
- |
TemporalSimpleType, |
20 |
|
- |
CalendarConstants, |
21 |
|
- |
SQLdateable |
|
18 |
+ |
public final class CalendarYMD extends AbstractCalendarYMD<CalendarYMD> implements SQLdateable |
22 |
19 |
|
{ |
23 |
|
- |
private static final long serialVersionUID = 2L; |
24 |
|
- |
|
25 |
|
- |
private final DateRes mDateRes; |
26 |
|
- |
private final int mYear, mMonth, mDay; |
|
20 |
+ |
private static final long serialVersionUID = 1L; |
27 |
21 |
|
|
28 |
22 |
|
@SuppressWarnings({"deprecation", "UnusedDeclaration"}) @Deprecated /** for Serialization */ |
29 |
23 |
|
protected CalendarYMD() |
30 |
24 |
|
{ |
31 |
|
- |
this( null, 0, 0, 0 ); |
32 |
|
- |
} |
33 |
|
- |
|
34 |
|
- |
public static CalendarYMD today() |
35 |
|
- |
{ |
36 |
|
- |
return new CalendarYMD( new Date() ); |
37 |
|
- |
} |
38 |
|
- |
|
39 |
|
- |
private CalendarYMD( DateRes pDateRes, int pYear, int pMonth, int pDay ) |
40 |
|
- |
{ |
41 |
|
- |
mDateRes = pDateRes; |
42 |
|
- |
mYear = pYear; |
43 |
|
- |
mMonth = pMonth; |
44 |
|
- |
mDay = pDay; |
45 |
|
- |
if ( isValidToDay() || (pDay != 0) ) |
46 |
|
- |
{ |
47 |
|
- |
mDateRes.validateDay( this, mYear, mMonth, mDay ); |
48 |
|
- |
} |
49 |
|
- |
else if ( isValidToMonth() || (pMonth != 0) ) |
50 |
|
- |
{ |
51 |
|
- |
mDateRes.validateMonth( this, mYear, mMonth ); |
52 |
|
- |
} |
53 |
|
- |
// Any Year is OK |
|
25 |
+ |
this( 0, 0, 0 ); |
54 |
26 |
|
} |
55 |
27 |
|
|
56 |
28 |
|
public CalendarYMD( int pYear, int pMonth, int pDay ) |
57 |
|
- |
throws IllegalArgumentException |
58 |
|
- |
{ |
59 |
|
- |
this( DateRes.ToDAY, pYear, pMonth, pDay ); |
60 |
|
- |
} |
61 |
|
- |
|
62 |
|
- |
public CalendarYMD( int pYear, int pMonth ) |
63 |
|
- |
throws IllegalArgumentException |
64 |
|
- |
{ |
65 |
|
- |
this( DateRes.ToMONTH, pYear, pMonth, 0 ); |
66 |
|
- |
} |
67 |
|
- |
|
68 |
|
- |
public CalendarYMD( int pYear ) |
69 |
|
- |
throws IllegalArgumentException |
70 |
|
- |
{ |
71 |
|
- |
this( DateRes.ToYEAR, pYear, 0, 0 ); |
72 |
|
- |
} |
73 |
|
- |
|
74 |
|
- |
public CalendarYMD( DateRes pDateRes, CalendarAccessorYMD pAccessor ) |
75 |
|
- |
throws IllegalArgumentException |
76 |
29 |
|
{ |
77 |
|
- |
this( pDateRes, |
78 |
|
- |
pAccessor.getYear(), |
79 |
|
- |
pDateRes.isValidToMonth() ? pAccessor.getMonth() : 0, |
80 |
|
- |
pDateRes.isValidToDay() ? pAccessor.getDay() : 0 ); |
|
30 |
+ |
super(pYear, pMonth, pDay); |
81 |
31 |
|
} |
82 |
32 |
|
|
83 |
33 |
|
public CalendarYMD( CalendarAccessorYMD pAccessor ) |
84 |
|
- |
throws IllegalArgumentException |
85 |
|
- |
{ |
86 |
|
- |
this( DateRes.ToDAY, pAccessor ); |
87 |
|
- |
} |
88 |
|
- |
|
89 |
|
- |
public CalendarYMD( DateRes pDateRes, Date pDate ) |
90 |
|
- |
throws IllegalArgumentException |
91 |
34 |
|
{ |
92 |
|
- |
this( pDateRes, new UtilDateAdaptor( pDate ) ); |
|
35 |
+ |
this( pAccessor.getYear(),pAccessor.getMonth(), pAccessor.getDay() ); |
93 |
36 |
|
} |
94 |
37 |
|
|
95 |
38 |
|
public CalendarYMD( Date pDate ) |
|
@@ -98,31 +41,9 @@ |
98 |
41 |
|
this( new UtilDateAdaptor( pDate ) ); |
99 |
42 |
|
} |
100 |
43 |
|
|
101 |
|
- |
public DateRes getDateRes() |
102 |
|
- |
{ |
103 |
|
- |
return mDateRes; |
104 |
|
- |
} |
105 |
|
- |
|
106 |
|
- |
/** |
107 |
|
- |
* Return a CalendarYMD (based on this) with the updated Resolution (reduction supported) |
108 |
|
- |
* |
109 |
|
- |
* @param pDateRes !null |
110 |
|
- |
* |
111 |
|
- |
* @throws IllegalArgumentException if <code>pDateRes</code> is null, or the Resolution is attempting to be increased |
112 |
|
- |
*/ |
113 |
|
- |
public CalendarYMD changeResolution( DateRes pDateRes ) |
114 |
|
- |
throws IllegalArgumentException |
|
44 |
+ |
public static CalendarYMD today() |
115 |
45 |
|
{ |
116 |
|
- |
Objects.assertNotNull( "DateRes", pDateRes ); |
117 |
|
- |
if ( mDateRes.equals( pDateRes ) ) |
118 |
|
- |
{ |
119 |
|
- |
return this; |
120 |
|
- |
} |
121 |
|
- |
if ( mDateRes.getIndex() < pDateRes.getIndex() ) |
122 |
|
- |
{ |
123 |
|
- |
throw new IllegalArgumentException( "May not add Resolution" ); |
124 |
|
- |
} |
125 |
|
- |
return new CalendarYMD( pDateRes, toUtilDateAdaptor() ); |
|
46 |
+ |
return new CalendarYMD( new Date() ); |
126 |
47 |
|
} |
127 |
48 |
|
|
128 |
49 |
|
/** |
|
@@ -133,7 +54,7 @@ |
133 |
54 |
|
public CalendarYMD forceFirstOfMonth() |
134 |
55 |
|
throws IllegalArgumentException |
135 |
56 |
|
{ |
136 |
|
- |
return minusDays( mDay - 1 ); |
|
57 |
+ |
return day( 1 ); |
137 |
58 |
|
} |
138 |
59 |
|
|
139 |
60 |
|
/** |
|
@@ -144,7 +65,7 @@ |
144 |
65 |
|
public CalendarYMD forceEndOfMonth() |
145 |
66 |
|
throws IllegalArgumentException |
146 |
67 |
|
{ |
147 |
|
- |
return addDays( Month.daysIn( getYear(), getMonth() ) - mDay ); |
|
68 |
+ |
return day( Month.daysIn( getYear(), getMonth() ) ); |
148 |
69 |
|
} |
149 |
70 |
|
|
150 |
71 |
|
/** |
|
@@ -158,138 +79,8 @@ |
158 |
79 |
|
return minusDays( getWeekDay().deltaTillBackward( pWeekDay ) ); |
159 |
80 |
|
} |
160 |
81 |
|
|
161 |
|
- |
/** |
162 |
|
- |
* Return a CalendarYMD with the Year set to the parameter, this is accomplished by utilizing addYears or minusYears as is appropriate (with their day |
163 |
|
- |
* adjusting logic). |
164 |
|
- |
*/ |
165 |
|
- |
public CalendarYMD year( int pYear ) |
166 |
|
- |
{ |
167 |
|
- |
return (mYear == pYear) ? this : (pYear > mYear) ? addYears( pYear - mYear ) : minusYears( mYear - pYear ); |
168 |
|
- |
} |
169 |
|
- |
|
170 |
|
- |
/** |
171 |
|
- |
* if after add pYears if was LeapDay and can not be LeapDay will be 1Mar. |
172 |
|
- |
*/ |
173 |
|
- |
public CalendarYMD addYears( int pYears ) |
174 |
|
- |
{ |
175 |
|
- |
return LLsetYear( mYear + pYears, true ); |
176 |
|
- |
} |
177 |
|
- |
|
178 |
|
- |
/** |
179 |
|
- |
* if after minus pYears if was LeapDay and can not be LeapDay will be 28Feb. |
180 |
|
- |
*/ |
181 |
|
- |
public CalendarYMD minusYears( int pYears ) |
182 |
|
- |
{ |
183 |
|
- |
return LLsetYear( mYear - pYears, false ); |
184 |
|
- |
} |
185 |
|
- |
|
186 |
|
- |
/** |
187 |
|
- |
* Return a CalendarYMD with the Month set to the parameter, this is accomplished by utilizing addMonths or minusMonths as is appropriate (with their day |
188 |
|
- |
* adjusting logic). |
189 |
|
- |
* |
190 |
|
- |
* @throws IllegalArgumentException if month is not between 1 & 12 inclusive, OR if the Resolution does not extend to Month. |
191 |
|
- |
*/ |
192 |
|
- |
public CalendarYMD month( int pMonth ) |
193 |
|
- |
throws IllegalArgumentException |
194 |
|
- |
{ |
195 |
|
- |
mDateRes.validateMonth( this, mYear, pMonth ); |
196 |
|
- |
return (mMonth == pMonth) ? this : (pMonth > mMonth) ? addMonths( pMonth - mMonth ) : minusMonths( mMonth - pMonth ); |
197 |
|
- |
} |
198 |
|
- |
|
199 |
|
- |
/** |
200 |
|
- |
* if after add pMonth there are insufficent days in the new month, the date will be set to the 1st of the next month. |
201 |
|
- |
* |
202 |
|
- |
* @throws IllegalArgumentException if the Resolution does not extend to Month. |
203 |
|
- |
*/ |
204 |
|
- |
public CalendarYMD addMonths( int pMonths ) |
205 |
|
- |
throws IllegalArgumentException |
206 |
|
- |
{ |
207 |
|
- |
return LLsetMonth( mMonth + pMonths, true ); |
208 |
|
- |
} |
209 |
|
- |
|
210 |
|
- |
/** |
211 |
|
- |
* if after minus pMonth there are insufficent days in the new month, the date will be set to the last day of the target month |
212 |
|
- |
* |
213 |
|
- |
* @throws IllegalArgumentException if the Resolution does not extend to Month. |
214 |
|
- |
*/ |
215 |
|
- |
public CalendarYMD minusMonths( int pMonths ) |
216 |
|
- |
throws IllegalArgumentException |
217 |
|
- |
{ |
218 |
|
- |
return LLsetMonth( mMonth - pMonths, false ); |
219 |
|
- |
} |
220 |
|
- |
|
221 |
|
- |
/** |
222 |
|
- |
* Return a CalendarYMD with the 'Day' field set to the parameter. |
223 |
|
- |
* |
224 |
|
- |
* @param pDay Must be between 1 and the max days in the <code>this</code>'s month |
225 |
|
- |
* |
226 |
|
- |
* @throws IllegalArgumentException if the <code>pDay</code> is invalid, OR the Resolution does not extend to Day. |
227 |
|
- |
*/ |
228 |
|
- |
public CalendarYMD day( int pDay ) |
229 |
|
- |
throws IllegalArgumentException |
230 |
|
- |
{ |
231 |
|
- |
return new CalendarYMD( mDateRes, mYear, mMonth, mDateRes.validateDay( this, mYear, mMonth, pDay ) ); |
232 |
|
- |
} |
233 |
|
- |
|
234 |
|
- |
/** |
235 |
|
- |
* Return a CalendarYMD adjusted forward by the <code>pDays</code> indicated. |
236 |
|
- |
* |
237 |
|
- |
* @throws IllegalArgumentException if the Resolution does not extend to Day. |
238 |
|
- |
*/ |
239 |
|
- |
public CalendarYMD addDays( int pDays ) |
240 |
|
- |
throws IllegalArgumentException |
241 |
|
- |
{ |
242 |
|
- |
return LLsetDay( mDay + pDays ); |
243 |
|
- |
} |
244 |
|
- |
|
245 |
|
- |
/** |
246 |
|
- |
* Return a CalendarYMD adjusted backward by the <code>pDays</code> indicated. |
247 |
|
- |
* |
248 |
|
- |
* @throws IllegalArgumentException if the Resolution does not extend to Day. |
249 |
|
- |
*/ |
250 |
|
- |
public CalendarYMD minusDays( int pDays ) |
251 |
|
- |
throws IllegalArgumentException |
252 |
|
- |
{ |
253 |
|
- |
return LLsetDay( mDay - pDays ); |
254 |
|
- |
} |
255 |
|
- |
|
256 |
|
- |
public boolean isValidToMonth() |
257 |
|
- |
{ |
258 |
|
- |
return mDateRes.isValidToMonth(); |
259 |
|
- |
} |
260 |
|
- |
|
261 |
|
- |
public boolean isValidToDay() |
262 |
|
- |
{ |
263 |
|
- |
return mDateRes.isValidToDay(); |
264 |
|
- |
} |
265 |
|
- |
|
266 |
|
- |
@Override |
267 |
|
- |
public int getYear() |
268 |
|
- |
{ |
269 |
|
- |
return mYear; |
270 |
|
- |
} |
271 |
|
- |
|
272 |
|
- |
/** |
273 |
|
- |
* @return 0 if not ValidToMonth, otherwise 1-12 |
274 |
|
- |
*/ |
275 |
|
- |
@Override |
276 |
|
- |
public int getMonth() |
277 |
|
- |
{ |
278 |
|
- |
return mMonth; |
279 |
|
- |
} |
280 |
|
- |
|
281 |
|
- |
/** |
282 |
|
- |
* @return 0 if not ValidToDay, otherwise 1-31 |
283 |
|
- |
*/ |
284 |
|
- |
@Override |
285 |
|
- |
public int getDay() |
286 |
|
- |
{ |
287 |
|
- |
return mDay; |
288 |
|
- |
} |
289 |
|
- |
|
290 |
82 |
|
public WeekDay getWeekDay() |
291 |
83 |
|
{ |
292 |
|
- |
validateToDay(); |
293 |
84 |
|
return WeekDay.valueOf( UtilDateAdaptor.dayOfWeek( toUtilDateAdaptor().getWallDate() ) ); |
294 |
85 |
|
} |
295 |
86 |
|
|
|
@@ -317,6 +108,8 @@ |
317 |
108 |
|
return new DaysDiff( this ).till( pThem ); |
318 |
109 |
|
} |
319 |
110 |
|
|
|
111 |
+ |
XXXXX |
|
112 |
+ |
|
320 |
113 |
|
/** |
321 |
114 |
|
* True if this is 'before' pThem. |
322 |
115 |
|
* <p/> |