|
@@ -6,7 +6,6 @@ |
6 |
6 |
|
import org.litesoft.core.simpletypes.nonpublic.*; |
7 |
7 |
|
import org.litesoft.core.simpletypes.temporal.nonpublic.*; |
8 |
8 |
|
import org.litesoft.core.typeutils.*; |
9 |
|
- |
import org.litesoft.core.typeutils.gregorian.*; |
10 |
9 |
|
|
11 |
10 |
|
/** |
12 |
11 |
|
* Format Control for YearMonthDayAccessor which provides varying levels of resolution based on the Format String |
|
@@ -46,7 +45,7 @@ |
46 |
45 |
|
|
47 |
46 |
|
private String mFormat = DEFAULT_YMD_FORMAT; |
48 |
47 |
|
|
49 |
|
- |
private int mResolutionIndex = DateRes.DAYindex; |
|
48 |
+ |
private DateRes mDateRes = DateRes.ToDAY; |
50 |
49 |
|
|
51 |
50 |
|
// Late Bound: |
52 |
51 |
|
private transient String mFieldOrder = null; |
|
@@ -68,13 +67,13 @@ |
68 |
67 |
|
case 6: // Month & Day |
69 |
68 |
|
// fall thru *** Common format used when the Year is implicit (e.g. 4JAN means the next January 4th) |
70 |
69 |
|
case 7: // Year, Month, & Day |
71 |
|
- |
mResolutionIndex = DateRes.DAYindex; |
|
70 |
+ |
mDateRes = DateRes.ToDAY; |
72 |
71 |
|
break; |
73 |
72 |
|
case 3: // Year & Month |
74 |
|
- |
mResolutionIndex = DateRes.MONTHindex; |
|
73 |
+ |
mDateRes = DateRes.ToMONTH; |
75 |
74 |
|
break; |
76 |
75 |
|
case 1: // Year Only |
77 |
|
- |
mResolutionIndex = DateRes.YEARindex; |
|
76 |
+ |
mDateRes = DateRes.ToYEAR; |
78 |
77 |
|
break; |
79 |
78 |
|
case 5: // Year & Day ? |
80 |
79 |
|
throw doesNotContain( DateRes.ToMONTH, "" ); |
|
@@ -89,6 +88,10 @@ |
89 |
88 |
|
|
90 |
89 |
|
public String format( YearMonthDayAccessor pDate ) |
91 |
90 |
|
{ |
|
91 |
+ |
if ( pDate == null ) |
|
92 |
+ |
{ |
|
93 |
+ |
return null; // TODO: Should this be ""? |
|
94 |
+ |
} |
92 |
95 |
|
StringBuilder sb = new StringBuilder(); |
93 |
96 |
|
for ( Chunk chunk : getToStringChunks() ) |
94 |
97 |
|
{ |
|
@@ -104,17 +107,17 @@ |
104 |
107 |
|
|
105 |
108 |
|
public DateRes getDateRes() |
106 |
109 |
|
{ |
107 |
|
- |
return DateRes.fromIndex( mResolutionIndex ); |
|
110 |
+ |
return mDateRes; |
108 |
111 |
|
} |
109 |
112 |
|
|
110 |
113 |
|
public boolean isValidToMonth() |
111 |
114 |
|
{ |
112 |
|
- |
return DateRes.MONTHindex <= mResolutionIndex; |
|
115 |
+ |
return mDateRes.isValidToMonth(); |
113 |
116 |
|
} |
114 |
117 |
|
|
115 |
118 |
|
public boolean isValidToDay() |
116 |
119 |
|
{ |
117 |
|
- |
return DateRes.DAYindex <= mResolutionIndex; |
|
120 |
+ |
return mDateRes.isValidToDay(); |
118 |
121 |
|
} |
119 |
122 |
|
|
120 |
123 |
|
@Override |
|
@@ -124,36 +127,6 @@ |
124 |
127 |
|
} |
125 |
128 |
|
|
126 |
129 |
|
/** |
127 |
|
- |
* Validate the date indicated against this' resolution. |
128 |
|
- |
* <p/> |
129 |
|
- |
* If the resolution is less than ToDAY, then pDay may be 0. |
130 |
|
- |
* If the resolution is less than ToMONTH, then pMonth may be 0, but then pDay MUST be 0. |
131 |
|
- |
* <p/> |
132 |
|
- |
* If pDay != 0, the complete date will be validated regardless of the resolution. |
133 |
|
- |
* If pMonth != 0, the month will be validated regardless of the resolution. |
134 |
|
- |
* |
135 |
|
- |
* @param pMonth 0-12, (0 ok if pDay is 0, AND resolution is ToYEAR) |
136 |
|
- |
* @param pDay 0-(28-31), (0 ok if the resolution is less than ToDAY) |
137 |
|
- |
*/ |
138 |
|
- |
public void validate( int pYear, int pMonth, int pDay ) |
139 |
|
- |
throws IllegalArgumentException |
140 |
|
- |
{ |
141 |
|
- |
if ( isValidToDay() || (pDay != 0) ) |
142 |
|
- |
{ |
143 |
|
- |
String error = Dates.checkValidity( pYear, pMonth, pDay ); |
144 |
|
- |
if ( error != null ) |
145 |
|
- |
{ |
146 |
|
- |
throw new IllegalArgumentException( error ); |
147 |
|
- |
} |
148 |
|
- |
} |
149 |
|
- |
else if ( isValidToMonth() || (pMonth != 0) ) |
150 |
|
- |
{ |
151 |
|
- |
LLcheckMonth( pYear, pMonth ); |
152 |
|
- |
} |
153 |
|
- |
// Any Year is OK |
154 |
|
- |
} |
155 |
|
- |
|
156 |
|
- |
/** |
157 |
130 |
|
* The expected order of the expected fields of a SimpleDate. |
158 |
131 |
|
* <p/> |
159 |
132 |
|
* E.g. "dd MMM yyyy" -> "dMy" |
|
@@ -224,27 +197,6 @@ |
224 |
197 |
|
", but no " + pDateRes.getFriendlyName() + " provided" ); |
225 |
198 |
|
} |
226 |
199 |
|
|
227 |
|
- |
protected int dayProvided( int pYear, int pMonth, int pDay ) |
228 |
|
- |
throws IllegalArgumentException |
229 |
|
- |
{ |
230 |
|
- |
monthProvided( pYear, pMonth ); |
231 |
|
- |
if ( !isValidToDay() ) |
232 |
|
- |
{ |
233 |
|
- |
throw doesNotContain( DateRes.ToDAY, ", but Day provided" ); |
234 |
|
- |
} |
235 |
|
- |
return LLcheckDay( pYear, pMonth, pDay ); |
236 |
|
- |
} |
237 |
|
- |
|
238 |
|
- |
protected int monthProvided( int pYear, int pMonth ) |
239 |
|
- |
throws IllegalArgumentException |
240 |
|
- |
{ |
241 |
|
- |
if ( !isValidToMonth() ) |
242 |
|
- |
{ |
243 |
|
- |
throw doesNotContain( DateRes.ToMONTH, ", but Month provided" ); |
244 |
|
- |
} |
245 |
|
- |
return LLcheckMonth( pYear, pMonth ); |
246 |
|
- |
} |
247 |
|
- |
|
248 |
200 |
|
protected void noMonthProvided() |
249 |
201 |
|
throws IllegalArgumentException |
250 |
202 |
|
{ |