Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/Calendar/bug4514831.java
47182 views
/*1* Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 451483126* @summary Confirm that GregorianCalendar.roll() works properly during transition from Daylight Saving Time to Standard Time.27*/2829import java.util.*;3031public class bug4514831 {3233public static void main(String[] args) {34Locale savedLocale = Locale.getDefault();35TimeZone savedTimeZone = TimeZone.getDefault();36boolean err = false;3738String golden_data1 ="27-28 28-29 29-30 30-31 31-1 1-2 2-3 ";39String golden_data2 ="27-28 28-29 29-30 30-31 31-25 25-26 26-27 ";40String golden_data3 ="1-8 8-15 15-22 22-29 29-1 1-8 8-15 ";4142try {43Locale.setDefault(Locale.US);44TimeZone.setDefault(TimeZone.getTimeZone("US/Pacific"));4546String test_roll = "";47GregorianCalendar c_roll = new GregorianCalendar(2001, Calendar.OCTOBER, 27);48for (int i=0; i < 7; i++) {49test_roll += c_roll.get(c_roll.DAY_OF_MONTH) + "-";50c_roll.roll(c_roll.DAY_OF_YEAR, true);51test_roll += c_roll.get(c_roll.DAY_OF_MONTH) + " ";52}53if (!test_roll.equals(golden_data1)) {54err = true;55System.err.println("Wrong roll(DAY_OF_YEAR) transition: got "+56test_roll + "expected " + golden_data1);57}5859test_roll = "";60c_roll = new GregorianCalendar(2001, Calendar.OCTOBER, 27);61c_roll.setFirstDayOfWeek(Calendar.THURSDAY);62for (int i=0; i < 7; i++) {63test_roll += c_roll.get(c_roll.DAY_OF_MONTH) + "-";64c_roll.roll(c_roll.DAY_OF_WEEK, true);65test_roll += c_roll.get(c_roll.DAY_OF_MONTH) + " ";66}67if (!test_roll.equals(golden_data2)) {68err = true;69System.err.println("Wrong roll(DAY_OF_WEEK) transition: got "+70test_roll + "expected " + golden_data2);71}7273test_roll = "";74c_roll = new GregorianCalendar(2001, Calendar.OCTOBER, 1);75for (int i=0; i < 7; i++) {76test_roll += c_roll.get(c_roll.DAY_OF_MONTH) + "-";77c_roll.roll(c_roll.DAY_OF_WEEK_IN_MONTH, true);78test_roll += c_roll.get(c_roll.DAY_OF_MONTH) + " ";79}80if (!test_roll.equals(golden_data3)) {81err = true;82System.err.println("Wrong roll(DAY_OF_WEEK_IN_MONTH) transition: got "+83test_roll + "expected " + golden_data3);84}85} finally {86Locale.setDefault(savedLocale);87TimeZone.setDefault(savedTimeZone);88}8990if (err) {91throw new RuntimeException("Wrong roll() transition");92}93}94}959697