|
@@ -36,9 +36,12 @@ |
36 |
36 |
|
chkCB( "2000/4/31" ); |
37 |
37 |
|
chkCB( "2100/2/29" ); // exception to Leap Day |
38 |
38 |
|
|
39 |
|
- |
// // Missing Parts |
40 |
|
- |
// chkCB( "yM", "1996" ); |
41 |
|
- |
// chkCB( "yMd", "1996/1" ); |
|
39 |
+ |
// Missing Parts |
|
40 |
+ |
chkCB( "1996" ); |
|
41 |
+ |
chkCB( "1996/1" ); |
|
42 |
+ |
|
|
43 |
+ |
// Too Many Parts |
|
44 |
+ |
chkCB( "1996/2/1/0" ); |
42 |
45 |
|
} |
43 |
46 |
|
|
44 |
47 |
|
private void chkCB( String pToYMD ) |
|
@@ -56,133 +59,107 @@ |
56 |
59 |
|
|
57 |
60 |
|
public void test_rtYMD() |
58 |
61 |
|
{ |
59 |
|
- |
chkRT( "y", "1996", "1996", DateRes.ToYEAR ); |
60 |
|
- |
chkRT( "yM", "2000/2", "2000/02", DateRes.ToMONTH ); |
61 |
|
- |
chkRT( "yMd", "2000/2/1", "2000/02/01", DateRes.ToDAY ); |
62 |
|
- |
chkRT( "yMd", "2000/12/1", "2000/12/01", DateRes.ToDAY ); |
63 |
|
- |
chkRT( "yMd", "2000/1/1", "2000/01/01", DateRes.ToDAY ); |
64 |
|
- |
chkRT( "yMd", "2000/1/31", "2000/01/31", DateRes.ToDAY ); |
65 |
|
- |
chkRT( "yMd", "2000/12/31", "2000/12/31", DateRes.ToDAY ); |
66 |
|
- |
chkRT( "yMd", "2000/2/29", "2000/02/29", DateRes.ToDAY ); // exception-exception Leap Day |
|
62 |
+ |
chkRT( "2000/2/1", "2000/02/01" ); |
|
63 |
+ |
chkRT( "2000/12/1", "2000/12/01" ); |
|
64 |
+ |
chkRT( "2000/1/1", "2000/01/01" ); |
|
65 |
+ |
chkRT( "2000/1/31", "2000/01/31" ); |
|
66 |
+ |
chkRT( "2000/12/31", "2000/12/31" ); |
|
67 |
+ |
chkRT( "2000/2/29", "2000/02/29" ); // exception-exception Leap Day |
67 |
68 |
|
} |
68 |
69 |
|
|
69 |
|
- |
private void chkRT( String pFormat, String pToYMD, String pFromYMD, DateRes pDateResExpected ) |
|
70 |
+ |
private void chkRT( String pToYMD, String pFromYMD ) |
70 |
71 |
|
{ |
71 |
|
- |
DateFormat zFormat = new DateFormat( pFormat ); |
72 |
|
- |
assertEquals( pDateResExpected, zFormat.getDateRes() ); |
73 |
72 |
|
CalendarYMD sd = CalendarYMD.fromYMD( pToYMD ); |
74 |
|
- |
assertEquals( pDateResExpected, sd.getDateRes() ); |
75 |
73 |
|
assertEquals( pFromYMD, sd.toYMD() ); |
76 |
74 |
|
} |
77 |
75 |
|
|
78 |
76 |
|
public void test_fromYMDAndToString() |
79 |
77 |
|
throws Exception |
80 |
78 |
|
{ |
81 |
|
- |
chk( DateFormat.DEFAULT_YMD_FORMAT, "1957/01/4", "04 Jan 1957", "dMy", 1957, 1, 4 ); |
82 |
|
- |
chk( "yy", "1996", "96", "y", 1996, 0, 0 ); |
83 |
|
- |
chk( "/yy", "1996", "/96", "y", 1996, 0, 0 ); |
84 |
|
- |
chk( "/ y:", "1996", "/ 1996:", "y", 1996, 0, 0 ); |
85 |
|
- |
chk( "/ yyy:", "1996", "/ 1996:", "y", 1996, 0, 0 ); |
86 |
|
- |
chk( "MM/dd/yy", "1957/01/04", "01/04/57", "Mdy", 1957, 1, 4 ); |
87 |
|
- |
chk( "init y/M/d fini", "1957/1/04", "init 1957/1/4 fini", "yMd", 1957, 1, 4 ); |
88 |
|
- |
chk( "dMMM", "1957/1/4", "4Jan", "dM", 1957, 1, 4 ); |
89 |
|
- |
chk( "dMMMyy", "1957/1/4", "4Jan57", "dMy", 1957, 1, 4 ); |
90 |
|
- |
chk( "dMMMyy", "1957/1/4", "4Jan57", "dMy", 1957, 1, 4 ); |
91 |
|
- |
chk( "d MMMM y", "1957/1/4", "4 January 1957", "dMy", 1957, 1, 4 ); |
92 |
|
- |
chk( "MMMMMM y", "1957 / 1", "January 1957", "My", 1957, 1, 0 ); |
|
79 |
+ |
chk( DateFormat.DEFAULT_YMD_FORMAT, "dMy", "1957/01/4", "04 Jan 1957", 1957, 1, 4 ); |
|
80 |
+ |
chk( "MM/dd/yy", "Mdy", "1957/01/04", "01/04/57", 1957, 1, 4 ); |
|
81 |
+ |
chk( "init y/M/d fini", "yMd", "1957/1/04", "init 1957/1/4 fini", 1957, 1, 4 ); |
|
82 |
+ |
chk( "dMMM", "dM", "1957/1/4", "4Jan", 1957, 1, 4 ); |
|
83 |
+ |
chk( "dMMMyy", "dMy", "1957/1/4", "4Jan57", 1957, 1, 4 ); |
|
84 |
+ |
chk( "dMMMyy", "dMy", "1957/1/4", "4Jan57", 1957, 1, 4 ); |
|
85 |
+ |
chk( "d MMMM y", "dMy", "1957/1/4", "4 January 1957", 1957, 1, 4 ); |
93 |
86 |
|
} |
94 |
87 |
|
|
95 |
|
- |
public void test_ContructorsAndToString() |
96 |
|
- |
throws Exception |
97 |
|
- |
{ |
98 |
|
- |
// Leap Day |
99 |
|
- |
chk( new CalendarYMD( 2004, 2, 29 ), "29 Feb 2004", "dMy", 2004, 2, 29 ); |
100 |
|
- |
// exception-exception Leap Day |
101 |
|
- |
chk( new CalendarYMD( 2000, 2, 29 ), "29 Feb 2000", "dMy", 2000, 2, 29 ); |
102 |
|
- |
|
103 |
|
- |
chk( new CalendarYMD( 1957, 1, 4 ), "04 Jan 1957", "dMy", 1957, 1, 4 ); |
104 |
|
- |
chk( "yy", 1996, "96", "y", 1996, 0, 0 ); |
105 |
|
- |
chk( "/yy", 1996, "/96", "y", 1996, 0, 0 ); |
106 |
|
- |
chk( "/ y:", 1996, "/ 1996:", "y", 1996, 0, 0 ); |
107 |
|
- |
chk( "/ yyy:", 1996, "/ 1996:", "y", 1996, 0, 0 ); |
108 |
|
- |
chk( "MM/dd/yy", 1957, 1, 4, "01/04/57", "Mdy", 1957, 1, 4 ); |
109 |
|
- |
chk( "init y/M/d fini", 1957, 1, 4, "init 1957/1/4 fini", "yMd", 1957, 1, 4 ); |
110 |
|
- |
chk( "dMMM", 1957, 1, 4, "4Jan", "dM", 1957, 1, 4 ); |
111 |
|
- |
chk( "dMMMyy", 1957, 1, 4, "4Jan57", "dMy", 1957, 1, 4 ); |
112 |
|
- |
chk( "dMMMyy", 1957, 1, 4, "4Jan57", "dMy", 1957, 1, 4 ); |
113 |
|
- |
chk( "d MMMM y", 1957, 1, 4, "4 January 1957", "dMy", 1957, 1, 4 ); |
114 |
|
- |
chk( "MMMMMM y", 1957, 1, "January 1957", "My", 1957, 1, 0 ); |
115 |
|
- |
chk( "MMMM d, y", 1957, 1, 4, "January 4, 1957", "Mdy", 1957, 1, 4 ); |
116 |
|
- |
chk( "(M/d/y) MMMM d", 1957, 1, 4, "(1/4/1957) January 4", "Mdy", 1957, 1, 4 ); |
117 |
|
- |
chk( "(M/d/y) ddMMM", 1957, 1, 4, "(1/4/1957) 04Jan", "Mdy", 1957, 1, 4 ); |
118 |
|
- |
|
119 |
|
- |
chk( new DateFormat( "MMMyy" ), new CalendarYMD( 1957, 1, 4 ).changeResolution( DateRes.ToMONTH ), "Jan57", "My", 1957, 1, 0 ); |
120 |
|
- |
} |
121 |
|
- |
|
122 |
|
- |
private void chk( String pDateFormat, String pDateToParse, String pToString, String pFieldOrder, int pYear, int pMonth, int pDay ) |
|
88 |
+ |
private void chk( String pDateFormat, String pFieldOrder, String pDateToParse, String pToString, int pYear, int pMonth, int pDay ) |
123 |
89 |
|
{ |
124 |
90 |
|
chk( new DateFormat( pDateFormat ), CalendarYMD.fromYMD( pDateToParse ), pToString, pFieldOrder, pYear, pMonth, pDay ); |
125 |
91 |
|
} |
126 |
92 |
|
|
127 |
|
- |
private void chk( String pDateFormat, int pYearSrc, String pToString, String pFieldOrder, int pYear, int pMonth, int pDay ) |
128 |
|
- |
{ |
129 |
|
- |
chk( new DateFormat( pDateFormat ), new CalendarYMD( pYearSrc ), pToString, pFieldOrder, pYear, pMonth, pDay ); |
130 |
|
- |
} |
131 |
|
- |
|
132 |
|
- |
private void chk( String pDateFormat, int pYearSrc, int pMonthSrc, String pToString, String pFieldOrder, int pYear, int pMonth, int pDay ) |
133 |
|
- |
{ |
134 |
|
- |
chk( new DateFormat( pDateFormat ), new CalendarYMD( pYearSrc, pMonthSrc ), pToString, pFieldOrder, pYear, pMonth, pDay ); |
135 |
|
- |
} |
136 |
|
- |
|
137 |
|
- |
private void chk( String pDateFormat, int pYearSrc, int pMonthSrc, int pDaySrc, String pToString, String pFieldOrder, int pYear, int pMonth, int pDay ) |
|
93 |
+ |
public void test_ContructorsAndToString() |
|
94 |
+ |
throws Exception |
138 |
95 |
|
{ |
139 |
|
- |
chk( new DateFormat( pDateFormat ), new CalendarYMD( pYearSrc, pMonthSrc, pDaySrc ), pToString, pFieldOrder, pYear, pMonth, pDay ); |
|
96 |
+ |
chk( "dd MMM yyyy", "dMy", 2004, 2, 29, "29 Feb 2004" ); // Leap Day |
|
97 |
+ |
chk( "dd MMM yyyy", "dMy", 2000, 2, 29, "29 Feb 2000" ); // exception-exception Leap Day |
|
98 |
+ |
chk( "dd MMM yyyy", "dMy", 1957, 1, 4, "04 Jan 1957" ); |
|
99 |
+ |
chk( "MM/dd/yy", "Mdy", 1957, 1, 4, "01/04/57" ); |
|
100 |
+ |
chk( "init y/M/d fini", "yMd", 1957, 1, 4, "init 1957/1/4 fini" ); |
|
101 |
+ |
chk( "dMMM", "dM", 1957, 1, 4, "4Jan" ); |
|
102 |
+ |
chk( "dMMMyy", "dMy", 1957, 1, 4, "4Jan57" ); |
|
103 |
+ |
chk( "dMMMyy", "dMy", 1957, 1, 4, "4Jan57" ); |
|
104 |
+ |
chk( "d MMMM y", "dMy", 1957, 1, 4, "4 January 1957" ); |
|
105 |
+ |
chk( "MMMM d, y", "Mdy", 1957, 1, 4, "January 4, 1957" ); |
|
106 |
+ |
chk( "(M/d/y) MMMM d", "Mdy", 1957, 1, 4, "(1/4/1957) January 4" ); |
|
107 |
+ |
chk( "(M/d/y) ddMMM", "Mdy", 1957, 1, 4, "(1/4/1957) 04Jan" ); |
140 |
108 |
|
} |
141 |
109 |
|
|
142 |
|
- |
private void chk( CalendarYMD pDate, String pToString, String pFieldOrder, int pYear, int pMonth, int pDay ) |
|
110 |
+ |
private void chk( String pDateFormat, String pFieldOrder, int pYear, int pMonth, int pDay, String pToString ) |
143 |
111 |
|
{ |
144 |
|
- |
chk( pDate.getDateRes().getDateFormat(), pDate, pToString, pFieldOrder, pYear, pMonth, pDay ); |
|
112 |
+ |
chk( new DateFormat( pDateFormat ), new CalendarYMD( pYear, pMonth, pDay ), pToString, pFieldOrder, pYear, pMonth, pDay ); |
145 |
113 |
|
} |
146 |
114 |
|
|
147 |
115 |
|
private void chk( DateFormat pFormat, CalendarYMD pDate, String pToString, String pFieldOrder, int pYear, int pMonth, int pDay ) |
148 |
116 |
|
{ |
149 |
|
- |
assertEquals( pFormat.getDateRes(), pDate.getDateRes() ); |
150 |
|
- |
|
151 |
117 |
|
assertEquals( pFieldOrder, pFormat.getFieldOrder() ); |
152 |
118 |
|
assertEquals( "Year", pYear, pDate.getYear() ); |
153 |
119 |
|
assertEquals( "Month", pMonth, pDate.getMonth() ); |
154 |
120 |
|
assertEquals( "Day", pDay, pDate.getDay() ); |
155 |
121 |
|
assertEquals( pToString, pFormat.format( pDate ) ); |
156 |
122 |
|
|
157 |
|
- |
if ( pDay != 0 ) |
158 |
|
- |
{ |
159 |
|
- |
CalendarYMD sd2 = pDate.addDays( 1 ).minusDays( 1 ); |
160 |
|
- |
assertEquals( "Year", pYear, sd2.getYear() ); |
161 |
|
- |
assertEquals( "Month", pMonth, sd2.getMonth() ); |
162 |
|
- |
assertEquals( "Day", pDay, sd2.getDay() ); |
163 |
|
- |
assertEquals( pDate, sd2 ); |
164 |
|
- |
} |
|
123 |
+ |
CalendarYMD sd2 = pDate.addDays( 1 ).minusDays( 1 ); |
|
124 |
+ |
assertEquals( "Year", pYear, sd2.getYear() ); |
|
125 |
+ |
assertEquals( "Month", pMonth, sd2.getMonth() ); |
|
126 |
+ |
assertEquals( "Day", pDay, sd2.getDay() ); |
|
127 |
+ |
assertEquals( pDate, sd2 ); |
165 |
128 |
|
} |
166 |
129 |
|
|
167 |
130 |
|
public void test_addYears() |
168 |
131 |
|
{ |
169 |
132 |
|
chk_addYears( "1957/01/04", 51, "2008/01/04" ); |
170 |
133 |
|
chk_addYears( "2000/01/15", -1, "1999/01/15" ); |
171 |
|
- |
chk_addYears( "2000/02/29", 1, "2001/03/01" ); |
172 |
|
- |
chk_addYears( "2000/02/29", -1, "1999/03/01" ); |
173 |
|
- |
chk_addYears( "1957/01", 51, "2008/01" ); |
174 |
|
- |
chk_addYears( "2000/01", -1, "1999/01" ); |
175 |
|
- |
chk_addYears( "2000/02", 1, "2001/02" ); |
176 |
|
- |
chk_addYears( "2000/02", -1, "1999/02" ); |
177 |
|
- |
chk_addYears( "1957", 51, "2008" ); |
178 |
|
- |
chk_addYears( "2000", -1, "1999" ); |
179 |
|
- |
chk_addYears( "2000", 1, "2001" ); |
|
134 |
+ |
chk_addYears( "2000/02/29", 1, "2001/02/28" ); |
|
135 |
+ |
chk_addYears( "2000/02/29", 0, "2000/02/29" ); |
|
136 |
+ |
chk_addYears( "2000/02/29", -1, "1999/02/28" ); |
180 |
137 |
|
} |
181 |
138 |
|
|
182 |
139 |
|
private void chk_addYears( String pDateYMD, int pAdjustBy, String pExpectedYMD ) |
183 |
140 |
|
{ |
184 |
|
- |
CalendarYMD sd = CalendarYMD.fromYMD( pDateYMD ).addYears( pAdjustBy ); |
185 |
|
- |
assertEquals( pExpectedYMD, sd.toYMD() ); |
|
141 |
+ |
CalendarYMD od = CalendarYMD.fromYMD( pDateYMD ); |
|
142 |
+ |
CalendarYMD nd = od.addYears( pAdjustBy ); |
|
143 |
+ |
assertEquals( pExpectedYMD, nd.toYMD() ); |
|
144 |
+ |
if ( pAdjustBy == 0 ) |
|
145 |
+ |
{ |
|
146 |
+ |
assertTrue( od == nd ); |
|
147 |
+ |
assertTrue( 0 == od.compareTo( nd ) ); |
|
148 |
+ |
assertTrue( od.afterOrEqual( nd ) ); |
|
149 |
+ |
assertTrue( od.beforeOrEqual( nd ) ); |
|
150 |
+ |
} |
|
151 |
+ |
else if ( pAdjustBy > 0 ) |
|
152 |
+ |
{ |
|
153 |
+ |
assertTrue( 0 > od.compareTo( nd ) ); |
|
154 |
+ |
assertFalse( od.afterOrEqual( nd ) ); |
|
155 |
+ |
assertTrue( od.beforeOrEqual( nd ) ); |
|
156 |
+ |
} |
|
157 |
+ |
else // pAdjustBy < 0 |
|
158 |
+ |
{ |
|
159 |
+ |
assertTrue( 0 < od.compareTo( nd ) ); |
|
160 |
+ |
assertTrue( od.afterOrEqual( nd ) ); |
|
161 |
+ |
assertFalse( od.beforeOrEqual( nd ) ); |
|
162 |
+ |
} |
186 |
163 |
|
} |
187 |
164 |
|
|
188 |
165 |
|
public void test_minusYears() |
|
@@ -190,101 +167,108 @@ |
190 |
167 |
|
chk_minusYears( "2008/01/04", 51, "1957/01/04" ); |
191 |
168 |
|
chk_minusYears( "2000/01/15", -1, "2001/01/15" ); |
192 |
169 |
|
chk_minusYears( "2000/02/29", 1, "1999/02/28" ); |
|
170 |
+ |
chk_minusYears( "2000/02/29", 0, "2000/02/29" ); |
193 |
171 |
|
chk_minusYears( "2000/02/29", -1, "2001/02/28" ); |
194 |
|
- |
chk_minusYears( "2008/01", 51, "1957/01" ); |
195 |
|
- |
chk_minusYears( "2000/01", -1, "2001/01" ); |
196 |
|
- |
chk_minusYears( "2000/02", 1, "1999/02" ); |
197 |
|
- |
chk_minusYears( "2000/02", -1, "2001/02" ); |
198 |
|
- |
chk_minusYears( "2008", 51, "1957" ); |
199 |
|
- |
chk_minusYears( "2000", -1, "2001" ); |
200 |
|
- |
chk_minusYears( "2000", 1, "1999" ); |
201 |
172 |
|
} |
202 |
173 |
|
|
203 |
174 |
|
private void chk_minusYears( String pDateYMD, int pAdjustBy, String pExpectedYMD ) |
204 |
175 |
|
{ |
205 |
|
- |
CalendarYMD sd = CalendarYMD.fromYMD( pDateYMD ).minusYears( pAdjustBy ); |
206 |
|
- |
assertEquals( pExpectedYMD, sd.toYMD() ); |
207 |
|
- |
} |
208 |
|
- |
|
209 |
|
- |
public void test_addMonths() |
210 |
|
- |
{ |
211 |
|
- |
CalendarYMD sd = new CalendarYMD( 2000 ); |
212 |
|
- |
try |
|
176 |
+ |
CalendarYMD od = CalendarYMD.fromYMD( pDateYMD ); |
|
177 |
+ |
CalendarYMD nd = od.minusYears( pAdjustBy ); |
|
178 |
+ |
assertEquals( pExpectedYMD, nd.toYMD() ); |
|
179 |
+ |
if ( pAdjustBy == 0 ) |
213 |
180 |
|
{ |
214 |
|
- |
sd.addMonths( 1 ); // expected to fail |
215 |
|
- |
fail( "Did Not fail on '" + sd + "': addMonths( 1 )" ); |
|
181 |
+ |
assertTrue( od == nd ); |
|
182 |
+ |
assertTrue( 0 == od.compareTo( nd ) ); |
|
183 |
+ |
assertTrue( od.afterOrEqual( nd ) ); |
|
184 |
+ |
assertTrue( od.beforeOrEqual( nd ) ); |
216 |
185 |
|
} |
217 |
|
- |
catch ( IllegalArgumentException expected ) |
|
186 |
+ |
else if ( pAdjustBy < 0 ) |
218 |
187 |
|
{ |
219 |
|
- |
// expected |
|
188 |
+ |
assertTrue( 0 > od.compareTo( nd ) ); |
|
189 |
+ |
assertFalse( od.afterOrEqual( nd ) ); |
|
190 |
+ |
assertTrue( od.beforeOrEqual( nd ) ); |
|
191 |
+ |
} |
|
192 |
+ |
else // pAdjustBy > 0 |
|
193 |
+ |
{ |
|
194 |
+ |
assertTrue( 0 < od.compareTo( nd ) ); |
|
195 |
+ |
assertTrue( od.afterOrEqual( nd ) ); |
|
196 |
+ |
assertFalse( od.beforeOrEqual( nd ) ); |
220 |
197 |
|
} |
221 |
|
- |
chk_addMonths( "1957/01/04", 2, "1957/03/04" ); |
222 |
|
- |
chk_addMonths( "2000/01/15", -1, "1999/12/15" ); |
223 |
|
- |
chk_addMonths( "2000/02/29", 12, "2001/03/01" ); |
224 |
|
- |
chk_addMonths( "2000/02/29", -12, "1999/03/01" ); |
225 |
|
- |
chk_addMonths( "1957/01", 2, "1957/03" ); |
226 |
|
- |
chk_addMonths( "2000/01", -1, "1999/12" ); |
227 |
|
- |
chk_addMonths( "2000/02", 12, "2001/02" ); |
228 |
|
- |
chk_addMonths( "2000/02", -12, "1999/02" ); |
229 |
198 |
|
} |
230 |
199 |
|
|
231 |
|
- |
private void chk_addMonths( String pDateYMD, int pAdjustBy, String pExpectedYMD ) |
|
200 |
+ |
public void test_addMonths() |
232 |
201 |
|
{ |
233 |
|
- |
CalendarYMD sd = CalendarYMD.fromYMD( pDateYMD ); |
234 |
|
- |
sd = sd.addMonths( pAdjustBy ); |
235 |
|
- |
assertEquals( pExpectedYMD, sd.toYMD() ); |
|
202 |
+ |
chk_addMonths( "1957/01/04", 2, "1957/03/04" ); |
|
203 |
+ |
chk_addMonths( "2000/01/15", -1, "1999/12/15" ); |
|
204 |
+ |
chk_addMonths( "2000/02/29", 12, "2001/02/28" ); |
|
205 |
+ |
chk_addMonths( "2000/02/29", 0, "2000/02/29" ); |
|
206 |
+ |
chk_addMonths( "2000/02/29", -12, "1999/02/28" ); |
236 |
207 |
|
} |
237 |
208 |
|
|
238 |
|
- |
public void test_minusMonths() |
|
209 |
+ |
private void chk_addMonths( String pDateYMD, int pAdjustBy, String pExpectedYMD ) |
239 |
210 |
|
{ |
240 |
|
- |
CalendarYMD sd = new CalendarYMD( 2000 ); |
241 |
|
- |
try |
|
211 |
+ |
CalendarYMD od = CalendarYMD.fromYMD( pDateYMD ); |
|
212 |
+ |
CalendarYMD nd = od.addMonths( pAdjustBy ); |
|
213 |
+ |
assertEquals( pExpectedYMD, nd.toYMD() ); |
|
214 |
+ |
if ( pAdjustBy == 0 ) |
242 |
215 |
|
{ |
243 |
|
- |
sd.minusMonths( 1 ); // expected failure |
244 |
|
- |
fail( "Did Not fail on '" + sd + "': minusMonths( 1 )" ); |
|
216 |
+ |
assertTrue( od == nd ); |
|
217 |
+ |
assertTrue( 0 == od.compareTo( nd ) ); |
|
218 |
+ |
assertTrue( od.afterOrEqual( nd ) ); |
|
219 |
+ |
assertTrue( od.beforeOrEqual( nd ) ); |
245 |
220 |
|
} |
246 |
|
- |
catch ( IllegalArgumentException expected ) |
|
221 |
+ |
else if ( pAdjustBy > 0 ) |
247 |
222 |
|
{ |
248 |
|
- |
// expected |
|
223 |
+ |
assertTrue( 0 > od.compareTo( nd ) ); |
|
224 |
+ |
assertFalse( od.afterOrEqual( nd ) ); |
|
225 |
+ |
assertTrue( od.beforeOrEqual( nd ) ); |
|
226 |
+ |
} |
|
227 |
+ |
else // pAdjustBy < 0 |
|
228 |
+ |
{ |
|
229 |
+ |
assertTrue( 0 < od.compareTo( nd ) ); |
|
230 |
+ |
assertTrue( od.afterOrEqual( nd ) ); |
|
231 |
+ |
assertFalse( od.beforeOrEqual( nd ) ); |
249 |
232 |
|
} |
|
233 |
+ |
} |
|
234 |
+ |
|
|
235 |
+ |
public void test_minusMonths() |
|
236 |
+ |
{ |
250 |
237 |
|
chk_minusMonths( "1957/03/04", 2, "1957/01/04" ); |
251 |
238 |
|
chk_minusMonths( "1999/12/15", -1, "2000/01/15" ); |
252 |
239 |
|
chk_minusMonths( "2000/02/29", 12, "1999/02/28" ); |
|
240 |
+ |
chk_minusMonths( "2000/02/29", 0, "2000/02/29" ); |
253 |
241 |
|
chk_minusMonths( "2000/02/29", -12, "2001/02/28" ); |
254 |
|
- |
chk_minusMonths( "1957/03", 2, "1957/01" ); |
255 |
|
- |
chk_minusMonths( "1999/12", -1, "2000/01" ); |
256 |
|
- |
chk_minusMonths( "2000/02", 12, "1999/02" ); |
257 |
|
- |
chk_minusMonths( "2000/02", -12, "2001/02" ); |
258 |
242 |
|
} |
259 |
243 |
|
|
260 |
244 |
|
private void chk_minusMonths( String pDateYMD, int pAdjustBy, String pExpectedYMD ) |
261 |
245 |
|
{ |
262 |
|
- |
CalendarYMD sd = CalendarYMD.fromYMD( pDateYMD ).minusMonths( pAdjustBy ); |
263 |
|
- |
assertEquals( pExpectedYMD, sd.toYMD() ); |
264 |
|
- |
} |
265 |
|
- |
|
266 |
|
- |
public void test_addDays_daysTill() |
267 |
|
- |
{ |
268 |
|
- |
CalendarYMD sd = new CalendarYMD( 2000 ); |
269 |
|
- |
try |
270 |
|
- |
{ |
271 |
|
- |
sd.addDays( 1 ); // expected failure |
272 |
|
- |
fail( "Did Not fail on '" + sd + "': addDays( 1 )" ); |
273 |
|
- |
} |
274 |
|
- |
catch ( IllegalArgumentException expected ) |
275 |
|
- |
{ |
276 |
|
- |
// expected |
277 |
|
- |
} |
278 |
|
- |
sd = new CalendarYMD( 2000, 1 ); |
279 |
|
- |
try |
|
246 |
+ |
CalendarYMD od = CalendarYMD.fromYMD( pDateYMD ); |
|
247 |
+ |
CalendarYMD nd = od.minusMonths( pAdjustBy ); |
|
248 |
+ |
assertEquals( pExpectedYMD, nd.toYMD() ); |
|
249 |
+ |
if ( pAdjustBy == 0 ) |
280 |
250 |
|
{ |
281 |
|
- |
sd.addDays( 1 ); // expected failure |
282 |
|
- |
fail( "Did Not fail on '" + sd + "': addDays( 1 )" ); |
|
251 |
+ |
assertTrue( od == nd ); |
|
252 |
+ |
assertTrue( 0 == od.compareTo( nd ) ); |
|
253 |
+ |
assertTrue( od.afterOrEqual( nd ) ); |
|
254 |
+ |
assertTrue( od.beforeOrEqual( nd ) ); |
283 |
255 |
|
} |
284 |
|
- |
catch ( IllegalArgumentException expected ) |
|
256 |
+ |
else if ( pAdjustBy < 0 ) |
285 |
257 |
|
{ |
286 |
|
- |
// expected |
|
258 |
+ |
assertTrue( 0 > od.compareTo( nd ) ); |
|
259 |
+ |
assertFalse( od.afterOrEqual( nd ) ); |
|
260 |
+ |
assertTrue( od.beforeOrEqual( nd ) ); |
|
261 |
+ |
} |
|
262 |
+ |
else // pAdjustBy > 0 |
|
263 |
+ |
{ |
|
264 |
+ |
assertTrue( 0 < od.compareTo( nd ) ); |
|
265 |
+ |
assertTrue( od.afterOrEqual( nd ) ); |
|
266 |
+ |
assertFalse( od.beforeOrEqual( nd ) ); |
287 |
267 |
|
} |
|
268 |
+ |
} |
|
269 |
+ |
|
|
270 |
+ |
public void test_addDays_daysTill() |
|
271 |
+ |
{ |
288 |
272 |
|
chk_addDays( "1957/01/04", 0, "1957/01/04" ); |
289 |
273 |
|
chk_addDays( "1957/01/04", 2, "1957/01/06" ); |
290 |
274 |
|
chk_addDays( "2000/01/15", -1, "2000/01/14" ); |
|
@@ -304,53 +288,33 @@ |
304 |
288 |
|
|
305 |
289 |
|
private void chk_addDays( String pDateYMD, int pAdjustBy, String pExpectedYMD ) |
306 |
290 |
|
{ |
307 |
|
- |
CalendarYMD osd = CalendarYMD.fromYMD( pDateYMD ); |
308 |
|
- |
CalendarYMD nsd = osd.addDays( pAdjustBy ); |
309 |
|
- |
assertEquals( pExpectedYMD, nsd.toYMD() ); |
310 |
|
- |
assertEquals( pAdjustBy, osd.daysTill( nsd ) ); |
|
291 |
+ |
CalendarYMD od = CalendarYMD.fromYMD( pDateYMD ); |
|
292 |
+ |
CalendarYMD nd = od.addDays( pAdjustBy ); |
|
293 |
+ |
assertEquals( pExpectedYMD, nd.toYMD() ); |
|
294 |
+ |
assertEquals( pAdjustBy, od.daysTill( nd ) ); |
311 |
295 |
|
if ( pAdjustBy == 0 ) |
312 |
296 |
|
{ |
313 |
|
- |
assertTrue( osd == nsd ); |
314 |
|
- |
assertTrue( 0 == osd.compareTo( nsd ) ); |
315 |
|
- |
assertFalse( osd.after( nsd ) ); |
316 |
|
- |
assertFalse( osd.before( nsd ) ); |
|
297 |
+ |
assertTrue( od == nd ); |
|
298 |
+ |
assertTrue( 0 == od.compareTo( nd ) ); |
|
299 |
+ |
assertTrue( od.afterOrEqual( nd ) ); |
|
300 |
+ |
assertTrue( od.beforeOrEqual( nd ) ); |
317 |
301 |
|
} |
318 |
302 |
|
else if ( pAdjustBy > 0 ) |
319 |
303 |
|
{ |
320 |
|
- |
assertTrue( 0 > osd.compareTo( nsd ) ); |
321 |
|
- |
assertFalse( osd.after( nsd ) ); |
322 |
|
- |
assertTrue( osd.before( nsd ) ); |
323 |
|
- |
} |
324 |
|
- |
else |
325 |
|
- |
{ |
326 |
|
- |
assertTrue( 0 < osd.compareTo( nsd ) ); |
327 |
|
- |
assertTrue( osd.after( nsd ) ); |
328 |
|
- |
assertFalse( osd.before( nsd ) ); |
|
304 |
+ |
assertTrue( 0 > od.compareTo( nd ) ); |
|
305 |
+ |
assertFalse( od.afterOrEqual( nd ) ); |
|
306 |
+ |
assertTrue( od.beforeOrEqual( nd ) ); |
|
307 |
+ |
} |
|
308 |
+ |
else // pAdjustBy < 0 |
|
309 |
+ |
{ |
|
310 |
+ |
assertTrue( 0 < od.compareTo( nd ) ); |
|
311 |
+ |
assertTrue( od.afterOrEqual( nd ) ); |
|
312 |
+ |
assertFalse( od.beforeOrEqual( nd ) ); |
329 |
313 |
|
} |
330 |
314 |
|
} |
331 |
315 |
|
|
332 |
316 |
|
public void test_minusDays_daysTill() |
333 |
317 |
|
{ |
334 |
|
- |
CalendarYMD sd = new CalendarYMD( 2000 ); |
335 |
|
- |
try |
336 |
|
- |
{ |
337 |
|
- |
sd.minusDays( 1 ); // expected failure |
338 |
|
- |
fail( "Did Not fail on '" + sd + "': minusDays( 1 )" ); |
339 |
|
- |
} |
340 |
|
- |
catch ( IllegalArgumentException expected ) |
341 |
|
- |
{ |
342 |
|
- |
// expected |
343 |
|
- |
} |
344 |
|
- |
sd = new CalendarYMD( 2000, 1 ); |
345 |
|
- |
try |
346 |
|
- |
{ |
347 |
|
- |
sd.minusDays( 1 ); // expected failure |
348 |
|
- |
fail( "Did Not fail on '" + sd + "': minusDays( 1 )" ); |
349 |
|
- |
} |
350 |
|
- |
catch ( IllegalArgumentException expected ) |
351 |
|
- |
{ |
352 |
|
- |
// expected |
353 |
|
- |
} |
354 |
318 |
|
chk_minusDays( "1957/01/04", 0, "1957/01/04" ); |
355 |
319 |
|
chk_minusDays( "1957/01/06", 2, "1957/01/04" ); |
356 |
320 |
|
chk_minusDays( "2000/01/14", -1, "2000/01/15" ); |
|
@@ -362,28 +326,28 @@ |
362 |
326 |
|
|
363 |
327 |
|
private void chk_minusDays( String pDateYMD, int pAdjustBy, String pExpectedYMD ) |
364 |
328 |
|
{ |
365 |
|
- |
CalendarYMD osd = CalendarYMD.fromYMD( pDateYMD ); |
366 |
|
- |
CalendarYMD nsd = osd.minusDays( pAdjustBy ); |
367 |
|
- |
assertEquals( pExpectedYMD, nsd.toYMD() ); |
368 |
|
- |
assertEquals( -pAdjustBy, osd.daysTill( nsd ) ); |
|
329 |
+ |
CalendarYMD od = CalendarYMD.fromYMD( pDateYMD ); |
|
330 |
+ |
CalendarYMD nd = od.minusDays( pAdjustBy ); |
|
331 |
+ |
assertEquals( pExpectedYMD, nd.toYMD() ); |
|
332 |
+ |
assertEquals( -pAdjustBy, od.daysTill( nd ) ); |
369 |
333 |
|
if ( pAdjustBy == 0 ) |
370 |
334 |
|
{ |
371 |
|
- |
assertTrue( osd == nsd ); |
372 |
|
- |
assertTrue( 0 == osd.compareTo( nsd ) ); |
373 |
|
- |
assertFalse( osd.after( nsd ) ); |
374 |
|
- |
assertFalse( osd.before( nsd ) ); |
|
335 |
+ |
assertTrue( od == nd ); |
|
336 |
+ |
assertTrue( 0 == od.compareTo( nd ) ); |
|
337 |
+ |
assertTrue( od.afterOrEqual( nd ) ); |
|
338 |
+ |
assertTrue( od.beforeOrEqual( nd ) ); |
375 |
339 |
|
} |
376 |
340 |
|
else if ( pAdjustBy < 0 ) |
377 |
341 |
|
{ |
378 |
|
- |
assertTrue( 0 > osd.compareTo( nsd ) ); |
379 |
|
- |
assertFalse( osd.after( nsd ) ); |
380 |
|
- |
assertTrue( osd.before( nsd ) ); |
381 |
|
- |
} |
382 |
|
- |
else |
383 |
|
- |
{ |
384 |
|
- |
assertTrue( 0 < osd.compareTo( nsd ) ); |
385 |
|
- |
assertTrue( osd.after( nsd ) ); |
386 |
|
- |
assertFalse( osd.before( nsd ) ); |
|
342 |
+ |
assertTrue( 0 > od.compareTo( nd ) ); |
|
343 |
+ |
assertFalse( od.afterOrEqual( nd ) ); |
|
344 |
+ |
assertTrue( od.beforeOrEqual( nd ) ); |
|
345 |
+ |
} |
|
346 |
+ |
else // pAdjustBy > 0 |
|
347 |
+ |
{ |
|
348 |
+ |
assertTrue( 0 < od.compareTo( nd ) ); |
|
349 |
+ |
assertTrue( od.afterOrEqual( nd ) ); |
|
350 |
+ |
assertFalse( od.beforeOrEqual( nd ) ); |
387 |
351 |
|
} |
388 |
352 |
|
} |
389 |
353 |
|
|
|
@@ -392,8 +356,8 @@ |
392 |
356 |
|
CalendarYMD sd = new CalendarYMD( 2000, 1, 1 ); |
393 |
357 |
|
try |
394 |
358 |
|
{ |
395 |
|
- |
sd.after( (CalendarYMD) null ); |
396 |
|
- |
fail( "Did Not fail on '" + sd + "': after( null )" ); |
|
359 |
+ |
sd.afterOrEqual( null ); |
|
360 |
+ |
fail( "Did Not fail on '" + sd + "': afterOrEqual( null )" ); |
397 |
361 |
|
} |
398 |
362 |
|
catch ( IllegalArgumentException expected ) |
399 |
363 |
|
{ |
|
@@ -401,8 +365,8 @@ |
401 |
365 |
|
} |
402 |
366 |
|
try |
403 |
367 |
|
{ |
404 |
|
- |
sd.before( (CalendarYMD) null ); |
405 |
|
- |
fail( "Did Not fail on '" + sd + "': before( null )" ); |
|
368 |
+ |
sd.beforeOrEqual( null ); |
|
369 |
+ |
fail( "Did Not fail on '" + sd + "': beforeOrEqual( null )" ); |
406 |
370 |
|
} |
407 |
371 |
|
catch ( IllegalArgumentException expected ) |
408 |
372 |
|
{ |