< prev index next >

test/jdk/java/util/Calendar/FieldStateTest.java

Print this page
8247706: Unintentional use of new Date(year...) with absolute year
Reviewed-by: naoto, rriggs, scolebourne
   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  */


 130         logln("Set to 2003/10 Mon of 43rd week of year (10/20: 4th week of month, 293rd day):");
 131         cal.clear();
 132         cal.set(YEAR, 2003);
 133         cal.set(DAY_OF_WEEK, MONDAY);
 134         cal.set(WEEK_OF_YEAR, 43);
 135         cal.getTime();
 136         if (!cal.checkDate(2003, OCTOBER, 20, MONDAY)) {
 137             errln(cal.getMessage());
 138         }
 139         if (!cal.checkFieldValue(WEEK_OF_MONTH, 4)) {
 140             errln(cal.getMessage());
 141         }
 142         if (!cal.checkFieldValue(DAY_OF_YEAR, 293)) {
 143             errln(cal.getMessage());
 144         }
 145 
 146         logln("Set day of week to SUNDAY and date to 2003/10/31. "
 147                 + "Then, getTime and set week of year to 43.");
 148 
 149         @SuppressWarnings("deprecation")
 150         Date d = new Date(2003 - 1990, OCTOBER, 31);
 151         cal.setTime(d);
 152         cal.set(DAY_OF_WEEK, SUNDAY);
 153         cal.set(2003, OCTOBER, 31); // 2003/10/31 is Friday.
 154         cal.set(ZONE_OFFSET, 0);
 155         cal.set(DST_OFFSET, 0);
 156 
 157         // This call should change the day of week to FRIDAY since the
 158         // selected field combination should be YEAR, MONTH and
 159         // DAY_OF_MONTH. The other calendar fields must be normalized
 160         // with the selected date.
 161         cal.getTime();
 162         cal.set(WEEK_OF_YEAR, 43);
 163         if (!cal.checkDate(2003, OCTOBER, 24, FRIDAY)) {
 164             errln(cal.getMessage());
 165         }
 166     }
 167 
 168     /*
 169      * 4916815: REGRESSION: Problem with java.util.Calendar VM 1.4.2-b28
 170      */


   1 /*
   2  * Copyright (c) 2003, 2020, 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  */


 130         logln("Set to 2003/10 Mon of 43rd week of year (10/20: 4th week of month, 293rd day):");
 131         cal.clear();
 132         cal.set(YEAR, 2003);
 133         cal.set(DAY_OF_WEEK, MONDAY);
 134         cal.set(WEEK_OF_YEAR, 43);
 135         cal.getTime();
 136         if (!cal.checkDate(2003, OCTOBER, 20, MONDAY)) {
 137             errln(cal.getMessage());
 138         }
 139         if (!cal.checkFieldValue(WEEK_OF_MONTH, 4)) {
 140             errln(cal.getMessage());
 141         }
 142         if (!cal.checkFieldValue(DAY_OF_YEAR, 293)) {
 143             errln(cal.getMessage());
 144         }
 145 
 146         logln("Set day of week to SUNDAY and date to 2003/10/31. "
 147                 + "Then, getTime and set week of year to 43.");
 148 
 149         @SuppressWarnings("deprecation")
 150         Date d = new Date(2003 - 1900, OCTOBER, 31);
 151         cal.setTime(d);
 152         cal.set(DAY_OF_WEEK, SUNDAY);
 153         cal.set(2003, OCTOBER, 31); // 2003/10/31 is Friday.
 154         cal.set(ZONE_OFFSET, 0);
 155         cal.set(DST_OFFSET, 0);
 156 
 157         // This call should change the day of week to FRIDAY since the
 158         // selected field combination should be YEAR, MONTH and
 159         // DAY_OF_MONTH. The other calendar fields must be normalized
 160         // with the selected date.
 161         cal.getTime();
 162         cal.set(WEEK_OF_YEAR, 43);
 163         if (!cal.checkDate(2003, OCTOBER, 24, FRIDAY)) {
 164             errln(cal.getMessage());
 165         }
 166     }
 167 
 168     /*
 169      * 4916815: REGRESSION: Problem with java.util.Calendar VM 1.4.2-b28
 170      */


< prev index next >