< prev index next >

test/jdk/java/util/Calendar/GregorianCutoverTest.java

Print this page

  1 /*
  2  * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 
 24 /*
 25  * @test
 26  * @bug 4359204 4928615 4743587 4956232 6459836 6549953
 27  * @library /java/text/testlib
 28  * @build Koyomi
 29  * @run main GregorianCutoverTest
 30  * @summary Unit tests related to the Gregorian cutover support.
 31  */
 32 
 33 import java.util.Date;
 34 import java.util.Locale;
 35 import java.util.TimeZone;
 36 
 37 import static java.util.GregorianCalendar.*;
 38 
 39 public class GregorianCutoverTest extends IntlTest {

 40 
 41     public static void main(String[] args) throws Exception {
 42         TimeZone tz = TimeZone.getDefault();
 43         Locale lc = Locale.getDefault();
 44         try {
 45             TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
 46             Locale.setDefault(Locale.US);
 47 
 48             new GregorianCutoverTest().run(args);
 49         } finally {
 50             TimeZone.setDefault(tz);
 51             Locale.setDefault(lc);
 52         }


 53     }
 54 

 55     /**
 56      * 4359204: GregorianCalendar.get(cal.DAY_OF_YEAR) is inconsistent for year 1582
 57      */

 58     public void Test4359204() {
 59         Koyomi cal = new Koyomi();
 60 
 61         cal.set(1582, JANUARY, 1);
 62         checkContinuity(cal, DAY_OF_YEAR);
 63         checkContinuity(cal, WEEK_OF_YEAR);
 64         cal.set(1582, OCTOBER, 1);
 65         checkContinuity(cal, WEEK_OF_MONTH);
 66 
 67         // JCK tests the cutover date 1970-1-1 (Epoch)
 68         cal.setGregorianChange(new Date(0));
 69         cal.set(1969, JANUARY, 1);
 70         checkContinuity(cal, DAY_OF_YEAR);
 71         checkContinuity(cal, WEEK_OF_YEAR);
 72         cal.set(1969, DECEMBER, 1);
 73         checkContinuity(cal, WEEK_OF_MONTH);
 74         cal.set(1970, JANUARY, 1);
 75         checkContinuity(cal, DAY_OF_YEAR);
 76         checkContinuity(cal, WEEK_OF_YEAR);
 77 

 83         checkContinuity(cal, DAY_OF_YEAR);
 84         checkContinuity(cal, WEEK_OF_YEAR);
 85         cal.set(49999, JANUARY, 1);
 86         checkContinuity(cal, DAY_OF_YEAR);
 87         checkContinuity(cal, WEEK_OF_YEAR);
 88         cal.set(50000, JANUARY, 20);
 89         checkContinuity(cal, DAY_OF_YEAR);
 90         checkContinuity(cal, WEEK_OF_YEAR);
 91 
 92         // Handling of "overlapping" dates may still be incorrect as
 93         // of 1.5. Also, there's no way to disambiguate "overlapping"
 94         // dates.
 95         // millis=-112033929600000: date=-1581-10-15T00:00:00.000Z
 96         cal.setGregorianChange(new Date(-112033929600000L));
 97         cal.set(ERA, AD);
 98         cal.set(-1581, JANUARY, 1);
 99         // The year should have 379 days.
100         checkContinuity(cal, DAY_OF_YEAR);
101         checkContinuity(cal, WEEK_OF_YEAR);
102 
103         logln("Default cutover");
104         cal = new Koyomi();
105         cal.set(1582, OCTOBER, 1);
106         logln("  roll --DAY_OF_MONTH from 1582/10/01");
107         cal.roll(DAY_OF_MONTH, -1);
108         if (!cal.checkDate(1582, OCTOBER, 31)) {
109             errln(cal.getMessage());
110         }
111         logln("  roll DAY_OF_MONTH+10 from 1582/10/31");
112         cal.roll(DAY_OF_MONTH, +10);
113         if (!cal.checkDate(1582, OCTOBER, 20)) {
114             errln(cal.getMessage());
115         }
116         logln("  roll DAY_OF_MONTH-10 from 1582/10/20");
117         cal.roll(DAY_OF_MONTH, -10);
118         if (!cal.checkDate(1582, OCTOBER, 31)) {
119             errln(cal.getMessage());
120         }
121         logln("  roll back one day further");
122         cal.roll(DAY_OF_MONTH, +1);
123         if (!cal.checkDate(1582, OCTOBER, 1)) {
124             errln(cal.getMessage());
125         }
126 
127         // should handle the gap between 1969/12/22 (Julian) to 1970/1/5 (Gregorian)
128         logln("Cutover date is 1970/1/5");
129         @SuppressWarnings("deprecation")
130         Date d1 = new Date(1970 - 1900, JANUARY, 5);
131         cal.setGregorianChange(d1);
132         cal.set(ERA, AD);
133         cal.set(YEAR, 1970);
134         logln("  Set DAY_OF_YEAR to the 28th day of 1970");
135         cal.set(DAY_OF_YEAR, 28);
136         if (!cal.checkDate(1970, FEBRUARY, 1)) {
137             errln(cal.getMessage());
138         }
139         if (!cal.checkFieldValue(WEEK_OF_YEAR, 5)) {
140             errln(cal.getMessage());
141         }
142         logln("  1969/12/22 should be the 356th day of the year.");
143         cal.set(1969, DECEMBER, 22);
144         if (!cal.checkFieldValue(DAY_OF_YEAR, 356)) {
145             errln(cal.getMessage());
146         }
147         logln("  Set DAY_OF_YEAR to autual maximum.");
148         int actualMaxDayOfYear = cal.getActualMaximum(DAY_OF_YEAR);
149         if (actualMaxDayOfYear != 356) {
150             errln("actual maximum of DAY_OF_YEAR: got " + actualMaxDayOfYear + ", expected 356");
151         }
152         cal.set(DAY_OF_YEAR, actualMaxDayOfYear);
153         if (!cal.checkDate(1969, DECEMBER, 22)) {
154             errln(cal.getMessage());
155         }
156         cal.set(1969, DECEMBER, 22);
157         cal.roll(DAY_OF_YEAR, +1);
158         logln("  Set to 1969/12/22 and roll DAY_OF_YEAR++");
159         if (!cal.checkDate(1969, JANUARY, 1)) {
160             errln(cal.getMessage());
161         }
162         logln("  1970/1/5 should be the first day of the year.");
163         cal.set(1970, JANUARY, 5);
164         if (!cal.checkFieldValue(DAY_OF_YEAR, 1)) {
165             errln(cal.getMessage());
166         }
167         logln("  roll --DAY_OF_MONTH from 1970/1/5");
168         cal.roll(DAY_OF_MONTH, -1);
169         if (!cal.checkDate(1970, JANUARY, 31)) {
170             errln(cal.getMessage());
171         }
172         logln("  roll back one day of month");
173         cal.roll(DAY_OF_MONTH, +1);
174         if (!cal.checkDate(1970, JANUARY, 5)) {
175             errln(cal.getMessage());
176         }
177 
178         // Test "missing" dates in non-lenient.
179         cal = new Koyomi(); // new instance for the default cutover
180         cal.setLenient(false);
181         try {
182             // the next day of 1582/10/4 (Julian) is 1582/10/15 (Gregorian)
183             logln("1582/10/10 doesn't exit with the default cutover.");
184             cal.set(1582, OCTOBER, 10);
185             cal.getTime();
186             errln("    Didn't throw IllegalArgumentException in non-lenient.");
187         } catch (IllegalArgumentException e) {
188         }
189     }
190 
191     private void checkContinuity(Koyomi cal, int field) {
192         cal.getTime();
193         logln(Koyomi.getFieldName(field) + " starting on " + cal.toDateString());
194         int max = cal.getActualMaximum(field);
195         for (int i = 1; i <= max; i++) {
196             logln(i + "    " + cal.toDateString());
197             if (!cal.checkFieldValue(field, i)) {
198                 errln("    " + cal.toDateString() + ":\t" + cal.getMessage());
199             }
200             cal.add(field, +1);
201         }
202     }
203 
204     /**
205      * 4928615: GregorianCalendar returns wrong dates after setGregorianChange
206      */

207     public void Test4928615() {
208         Koyomi cal = new Koyomi();
209         logln("Today is 2003/10/1 Gregorian.");
210         @SuppressWarnings("deprecation")
211         Date x = new Date(2003 - 1900, 10 - 1, 1);
212         cal.setTime(x);
213 
214         logln("  Changing the cutover date to yesterday...");
215         cal.setGregorianChange(new Date(x.getTime() - (24 * 3600 * 1000)));
216         if (!cal.checkDate(2003, OCTOBER, 1)) {
217             errln("    " + cal.getMessage());
218         }
219         logln("  Changing the cutover date to tomorrow...");
220         cal.setGregorianChange(new Date(x.getTime() + (24 * 3600 * 1000)));
221         if (!cal.checkDate(2003, SEPTEMBER, 18)) {
222             errln("    " + cal.getMessage());
223         }
224     }
225 
226     /**
227      * 4743587: GregorianCalendar.getLeastMaximum() returns wrong values
228      */

229     public void Test4743587() {
230         Koyomi cal = new Koyomi();
231         Koyomi cal2 = (Koyomi) cal.clone();
232         logln("getLeastMaximum should handle cutover year.\n"
233                 + "  default cutover date");
234         if (!cal.checkLeastMaximum(DAY_OF_YEAR, 365 - 10)) {
235             errln("    " + cal.getMessage());
236         }
237         if (!cal.checkLeastMaximum(WEEK_OF_YEAR, 52 - ((10 + 6) / 7))) {
238             errln("    " + cal.getMessage());
239         }
240         // Corrected for 4956232
241         if (!cal.checkLeastMaximum(DAY_OF_MONTH, 28)) {
242             errln("    " + cal.getMessage());
243         }
244         if (!cal.checkLeastMaximum(WEEK_OF_MONTH, 3)) {
245             errln("    " + cal.getMessage());
246         }
247         if (!cal.checkLeastMaximum(DAY_OF_WEEK_IN_MONTH, 3)) {
248             errln("    " + cal.getMessage());
249         }
250         // make sure that getLeastMaximum calls didn't affect the date
251         if (!cal.equals(cal2)) {
252             errln("    getLeastMaximum calls modified the object.");
253         }
254         if (!cal.checkGreatestMinimum(DAY_OF_MONTH, 1)) {
255             errln("    " + cal.getMessage());
256         }
257 
258         logln("  changing the date to 1582/10/20 for actual min/max tests");
259         cal.set(1582, OCTOBER, 20);
260         if (!cal.checkActualMinimum(DAY_OF_MONTH, 1)) {
261             errln("    " + cal.getMessage());
262         }
263         if (!cal.checkActualMaximum(DAY_OF_MONTH, 31)) {
264             errln("    " + cal.getMessage());
265         }
266 
267         cal = new Koyomi();
268         logln("Change the cutover date to 1970/1/5.");
269         @SuppressWarnings("deprecation")
270         Date d = new Date(1970 - 1900, 0, 5);
271         cal.setGregorianChange(d);
272         if (!cal.checkLeastMaximum(DAY_OF_YEAR, 356)) {
273             errln("    " + cal.getMessage());
274         }
275         if (!cal.checkLeastMaximum(DAY_OF_MONTH, 22)) {
276             errln("    " + cal.getMessage());
277         }
278         if (!cal.checkGreatestMinimum(DAY_OF_MONTH, 5)) {
279             errln("    " + cal.getMessage());
280         }
281         cal.set(1970, JANUARY, 10);
282         if (!cal.checkActualMinimum(DAY_OF_MONTH, 5)) {
283             errln("    " + cal.getMessage());
284         }
285         if (!cal.checkActualMaximum(DAY_OF_MONTH, 31)) {
286             errln("    " + cal.getMessage());
287         }
288     }
289 
290     /**
291      * 6459836: (cal) GregorianCalendar set method provides wrong result
292      */

293     public void Test6459836() {
294         int hour = 13865672;
295         Koyomi gc1 = new Koyomi();
296         gc1.clear();
297         gc1.set(1, JANUARY, 1, 0, 0, 0);
298         gc1.set(HOUR_OF_DAY, hour);
299         if (!gc1.checkDate(1582, OCTOBER, 4)) {
300             errln("test case 1: " + gc1.getMessage());
301         }
302         gc1.clear();
303         gc1.set(1, JANUARY, 1, 0, 0, 0);
304         gc1.set(HOUR_OF_DAY, hour + 24);
305         if (!gc1.checkDate(1582, OCTOBER, 15)) {
306             errln("test case 2: " + gc1.getMessage());
307         }
308     }
309 
310     /**
311      * 6549953 (cal) WEEK_OF_YEAR and DAY_OF_YEAR calculation problems around Gregorian cutover
312      */

313     public void Test6549953() {
314         Koyomi cal = new Koyomi();
315 
316         cal.set(YEAR, 1582);
317         cal.set(WEEK_OF_YEAR, 42);
318         cal.set(DAY_OF_WEEK, FRIDAY);
319         cal.checkFieldValue(WEEK_OF_YEAR, 42);
320         cal.checkFieldValue(DAY_OF_WEEK, FRIDAY);
321         if (!cal.checkDate(1582, OCTOBER, 29)) {
322             errln(cal.getMessage());
323         }
324         cal.clear();
325         cal.set(1582, OCTOBER, 1);
326         cal.set(DAY_OF_YEAR, 292);
327         if (!cal.checkDate(1582, OCTOBER, 29)) {
328             errln(cal.getMessage());
329         }
330     }
331 }

  1 /*
  2  * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 
 24 /*
 25  * @test
 26  * @bug 4359204 4928615 4743587 4956232 6459836 6549953
 27  * @run junit/othervm GregorianCutoverTest


 28  * @summary Unit tests related to the Gregorian cutover support.
 29  */
 30 
 31 import java.util.Date;
 32 import java.util.Locale;
 33 import java.util.TimeZone;
 34 
 35 import static java.util.GregorianCalendar.*;
 36 
 37 import org.junit.jupiter.api.Test;
 38 import org.junit.jupiter.api.BeforeAll;
 39 
 40 import static org.junit.jupiter.api.Assertions.fail;





 41 
 42 public class GregorianCutoverTest {
 43 
 44     // Change JVM default Locale and TimeZone
 45     @BeforeAll
 46     static void initAll() {
 47         Locale.setDefault(Locale.US);
 48         TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
 49     }
 50 
 51 
 52     /**
 53      * 4359204: GregorianCalendar.get(cal.DAY_OF_YEAR) is inconsistent for year 1582
 54      */
 55     @Test
 56     public void Test4359204() {
 57         Koyomi cal = new Koyomi();
 58 
 59         cal.set(1582, JANUARY, 1);
 60         checkContinuity(cal, DAY_OF_YEAR);
 61         checkContinuity(cal, WEEK_OF_YEAR);
 62         cal.set(1582, OCTOBER, 1);
 63         checkContinuity(cal, WEEK_OF_MONTH);
 64 
 65         // JCK tests the cutover date 1970-1-1 (Epoch)
 66         cal.setGregorianChange(new Date(0));
 67         cal.set(1969, JANUARY, 1);
 68         checkContinuity(cal, DAY_OF_YEAR);
 69         checkContinuity(cal, WEEK_OF_YEAR);
 70         cal.set(1969, DECEMBER, 1);
 71         checkContinuity(cal, WEEK_OF_MONTH);
 72         cal.set(1970, JANUARY, 1);
 73         checkContinuity(cal, DAY_OF_YEAR);
 74         checkContinuity(cal, WEEK_OF_YEAR);
 75 

 81         checkContinuity(cal, DAY_OF_YEAR);
 82         checkContinuity(cal, WEEK_OF_YEAR);
 83         cal.set(49999, JANUARY, 1);
 84         checkContinuity(cal, DAY_OF_YEAR);
 85         checkContinuity(cal, WEEK_OF_YEAR);
 86         cal.set(50000, JANUARY, 20);
 87         checkContinuity(cal, DAY_OF_YEAR);
 88         checkContinuity(cal, WEEK_OF_YEAR);
 89 
 90         // Handling of "overlapping" dates may still be incorrect as
 91         // of 1.5. Also, there's no way to disambiguate "overlapping"
 92         // dates.
 93         // millis=-112033929600000: date=-1581-10-15T00:00:00.000Z
 94         cal.setGregorianChange(new Date(-112033929600000L));
 95         cal.set(ERA, AD);
 96         cal.set(-1581, JANUARY, 1);
 97         // The year should have 379 days.
 98         checkContinuity(cal, DAY_OF_YEAR);
 99         checkContinuity(cal, WEEK_OF_YEAR);
100 
101         System.out.println("Default cutover");
102         cal = new Koyomi();
103         cal.set(1582, OCTOBER, 1);
104         System.out.println("  roll --DAY_OF_MONTH from 1582/10/01");
105         cal.roll(DAY_OF_MONTH, -1);
106         if (!cal.checkDate(1582, OCTOBER, 31)) {
107             fail(cal.getMessage());
108         }
109         System.out.println("  roll DAY_OF_MONTH+10 from 1582/10/31");
110         cal.roll(DAY_OF_MONTH, +10);
111         if (!cal.checkDate(1582, OCTOBER, 20)) {
112             fail(cal.getMessage());
113         }
114         System.out.println("  roll DAY_OF_MONTH-10 from 1582/10/20");
115         cal.roll(DAY_OF_MONTH, -10);
116         if (!cal.checkDate(1582, OCTOBER, 31)) {
117             fail(cal.getMessage());
118         }
119         System.out.println("  roll back one day further");
120         cal.roll(DAY_OF_MONTH, +1);
121         if (!cal.checkDate(1582, OCTOBER, 1)) {
122             fail(cal.getMessage());
123         }
124 
125         // should handle the gap between 1969/12/22 (Julian) to 1970/1/5 (Gregorian)
126         System.out.println("Cutover date is 1970/1/5");
127         @SuppressWarnings("deprecation")
128         Date d1 = new Date(1970 - 1900, JANUARY, 5);
129         cal.setGregorianChange(d1);
130         cal.set(ERA, AD);
131         cal.set(YEAR, 1970);
132         System.out.println("  Set DAY_OF_YEAR to the 28th day of 1970");
133         cal.set(DAY_OF_YEAR, 28);
134         if (!cal.checkDate(1970, FEBRUARY, 1)) {
135             fail(cal.getMessage());
136         }
137         if (!cal.checkFieldValue(WEEK_OF_YEAR, 5)) {
138             fail(cal.getMessage());
139         }
140         System.out.println("  1969/12/22 should be the 356th day of the year.");
141         cal.set(1969, DECEMBER, 22);
142         if (!cal.checkFieldValue(DAY_OF_YEAR, 356)) {
143             fail(cal.getMessage());
144         }
145         System.out.println("  Set DAY_OF_YEAR to autual maximum.");
146         int actualMaxDayOfYear = cal.getActualMaximum(DAY_OF_YEAR);
147         if (actualMaxDayOfYear != 356) {
148             fail("actual maximum of DAY_OF_YEAR: got " + actualMaxDayOfYear + ", expected 356");
149         }
150         cal.set(DAY_OF_YEAR, actualMaxDayOfYear);
151         if (!cal.checkDate(1969, DECEMBER, 22)) {
152             fail(cal.getMessage());
153         }
154         cal.set(1969, DECEMBER, 22);
155         cal.roll(DAY_OF_YEAR, +1);
156         System.out.println("  Set to 1969/12/22 and roll DAY_OF_YEAR++");
157         if (!cal.checkDate(1969, JANUARY, 1)) {
158             fail(cal.getMessage());
159         }
160         System.out.println("  1970/1/5 should be the first day of the year.");
161         cal.set(1970, JANUARY, 5);
162         if (!cal.checkFieldValue(DAY_OF_YEAR, 1)) {
163             fail(cal.getMessage());
164         }
165         System.out.println("  roll --DAY_OF_MONTH from 1970/1/5");
166         cal.roll(DAY_OF_MONTH, -1);
167         if (!cal.checkDate(1970, JANUARY, 31)) {
168             fail(cal.getMessage());
169         }
170         System.out.println("  roll back one day of month");
171         cal.roll(DAY_OF_MONTH, +1);
172         if (!cal.checkDate(1970, JANUARY, 5)) {
173             fail(cal.getMessage());
174         }
175 
176         // Test "missing" dates in non-lenient.
177         cal = new Koyomi(); // new instance for the default cutover
178         cal.setLenient(false);
179         try {
180             // the next day of 1582/10/4 (Julian) is 1582/10/15 (Gregorian)
181             System.out.println("1582/10/10 doesn't exit with the default cutover.");
182             cal.set(1582, OCTOBER, 10);
183             cal.getTime();
184             fail("    Didn't throw IllegalArgumentException in non-lenient.");
185         } catch (IllegalArgumentException e) {
186         }
187     }
188 
189     private void checkContinuity(Koyomi cal, int field) {
190         cal.getTime();
191         System.out.println(Koyomi.getFieldName(field) + " starting on " + cal.toDateString());
192         int max = cal.getActualMaximum(field);
193         for (int i = 1; i <= max; i++) {
194             System.out.println(i + "    " + cal.toDateString());
195             if (!cal.checkFieldValue(field, i)) {
196                 fail("    " + cal.toDateString() + ":\t" + cal.getMessage());
197             }
198             cal.add(field, +1);
199         }
200     }
201 
202     /**
203      * 4928615: GregorianCalendar returns wrong dates after setGregorianChange
204      */
205     @Test
206     public void Test4928615() {
207         Koyomi cal = new Koyomi();
208         System.out.println("Today is 2003/10/1 Gregorian.");
209         @SuppressWarnings("deprecation")
210         Date x = new Date(2003 - 1900, 10 - 1, 1);
211         cal.setTime(x);
212 
213         System.out.println("  Changing the cutover date to yesterday...");
214         cal.setGregorianChange(new Date(x.getTime() - (24 * 3600 * 1000)));
215         if (!cal.checkDate(2003, OCTOBER, 1)) {
216             fail("    " + cal.getMessage());
217         }
218         System.out.println("  Changing the cutover date to tomorrow...");
219         cal.setGregorianChange(new Date(x.getTime() + (24 * 3600 * 1000)));
220         if (!cal.checkDate(2003, SEPTEMBER, 18)) {
221             fail("    " + cal.getMessage());
222         }
223     }
224 
225     /**
226      * 4743587: GregorianCalendar.getLeastMaximum() returns wrong values
227      */
228     @Test
229     public void Test4743587() {
230         Koyomi cal = new Koyomi();
231         Koyomi cal2 = (Koyomi) cal.clone();
232         System.out.println("getLeastMaximum should handle cutover year.\n"
233                 + "  default cutover date");
234         if (!cal.checkLeastMaximum(DAY_OF_YEAR, 365 - 10)) {
235             fail("    " + cal.getMessage());
236         }
237         if (!cal.checkLeastMaximum(WEEK_OF_YEAR, 52 - ((10 + 6) / 7))) {
238             fail("    " + cal.getMessage());
239         }
240         // Corrected for 4956232
241         if (!cal.checkLeastMaximum(DAY_OF_MONTH, 28)) {
242             fail("    " + cal.getMessage());
243         }
244         if (!cal.checkLeastMaximum(WEEK_OF_MONTH, 3)) {
245             fail("    " + cal.getMessage());
246         }
247         if (!cal.checkLeastMaximum(DAY_OF_WEEK_IN_MONTH, 3)) {
248             fail("    " + cal.getMessage());
249         }
250         // make sure that getLeastMaximum calls didn't affect the date
251         if (!cal.equals(cal2)) {
252             fail("    getLeastMaximum calls modified the object.");
253         }
254         if (!cal.checkGreatestMinimum(DAY_OF_MONTH, 1)) {
255             fail("    " + cal.getMessage());
256         }
257 
258         System.out.println("  changing the date to 1582/10/20 for actual min/max tests");
259         cal.set(1582, OCTOBER, 20);
260         if (!cal.checkActualMinimum(DAY_OF_MONTH, 1)) {
261             fail("    " + cal.getMessage());
262         }
263         if (!cal.checkActualMaximum(DAY_OF_MONTH, 31)) {
264             fail("    " + cal.getMessage());
265         }
266 
267         cal = new Koyomi();
268         System.out.println("Change the cutover date to 1970/1/5.");
269         @SuppressWarnings("deprecation")
270         Date d = new Date(1970 - 1900, 0, 5);
271         cal.setGregorianChange(d);
272         if (!cal.checkLeastMaximum(DAY_OF_YEAR, 356)) {
273             fail("    " + cal.getMessage());
274         }
275         if (!cal.checkLeastMaximum(DAY_OF_MONTH, 22)) {
276             fail("    " + cal.getMessage());
277         }
278         if (!cal.checkGreatestMinimum(DAY_OF_MONTH, 5)) {
279             fail("    " + cal.getMessage());
280         }
281         cal.set(1970, JANUARY, 10);
282         if (!cal.checkActualMinimum(DAY_OF_MONTH, 5)) {
283             fail("    " + cal.getMessage());
284         }
285         if (!cal.checkActualMaximum(DAY_OF_MONTH, 31)) {
286             fail("    " + cal.getMessage());
287         }
288     }
289 
290     /**
291      * 6459836: (cal) GregorianCalendar set method provides wrong result
292      */
293     @Test
294     public void Test6459836() {
295         int hour = 13865672;
296         Koyomi gc1 = new Koyomi();
297         gc1.clear();
298         gc1.set(1, JANUARY, 1, 0, 0, 0);
299         gc1.set(HOUR_OF_DAY, hour);
300         if (!gc1.checkDate(1582, OCTOBER, 4)) {
301             fail("test case 1: " + gc1.getMessage());
302         }
303         gc1.clear();
304         gc1.set(1, JANUARY, 1, 0, 0, 0);
305         gc1.set(HOUR_OF_DAY, hour + 24);
306         if (!gc1.checkDate(1582, OCTOBER, 15)) {
307             fail("test case 2: " + gc1.getMessage());
308         }
309     }
310 
311     /**
312      * 6549953 (cal) WEEK_OF_YEAR and DAY_OF_YEAR calculation problems around Gregorian cutover
313      */
314     @Test
315     public void Test6549953() {
316         Koyomi cal = new Koyomi();
317 
318         cal.set(YEAR, 1582);
319         cal.set(WEEK_OF_YEAR, 42);
320         cal.set(DAY_OF_WEEK, FRIDAY);
321         cal.checkFieldValue(WEEK_OF_YEAR, 42);
322         cal.checkFieldValue(DAY_OF_WEEK, FRIDAY);
323         if (!cal.checkDate(1582, OCTOBER, 29)) {
324             fail(cal.getMessage());
325         }
326         cal.clear();
327         cal.set(1582, OCTOBER, 1);
328         cal.set(DAY_OF_YEAR, 292);
329         if (!cal.checkDate(1582, OCTOBER, 29)) {
330             fail(cal.getMessage());
331         }
332     }
333 }
< prev index next >