Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/TimeZone/Bug6772689.java
38821 views
/*1* Copyright (c) 2011, 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 677268926* @summary Test for standard-to-daylight transitions at midnight:27* date stays on the given day.28*/2930import java.util.Calendar;31import java.util.Date;32import java.util.GregorianCalendar;33import java.util.TimeZone;34import static java.util.GregorianCalendar.*;3536public class Bug6772689 {37private static final int BEGIN_YEAR = 2035;38private static final int END_YEAR = BEGIN_YEAR + 28;3940public static void main(String[] args) {41TimeZone defaultTimeZone = TimeZone.getDefault();42int errors = 0;4344Calendar cal = new GregorianCalendar(BEGIN_YEAR, MARCH, 1);45String[] tzids = TimeZone.getAvailableIDs();46try {47for (String id : tzids) {48TimeZone tz = TimeZone.getTimeZone(id);49if (!tz.useDaylightTime()) {50continue;51}52TimeZone.setDefault(tz);5354dateloop:55// Use future dates because sun.util.calendar.ZoneInfo56// delegates offset transition calculations to a SimpleTimeZone57// (after 2038 as of JDK7).58for (int year = BEGIN_YEAR; year < END_YEAR; year++) {59for (int month = MARCH; month <= NOVEMBER; month++) {60cal.set(year, month, 1, 15, 0, 0);61int maxDom = cal.getActualMaximum(DAY_OF_MONTH);62for (int dom = 1; dom <= maxDom; dom++) {63Date date = new Date(year - 1900, month, dom);64if (date.getYear()+1900 != year65|| date.getMonth() != month66|| date.getDate() != dom) {67System.err.printf("%s: got %04d-%02d-%02d, expected %04d-%02d-%02d%n",68id,69date.getYear() + 1900,70date.getMonth() + 1,71date.getDate(),72year,73month + 1,74dom);75errors++;76break dateloop;77}78}79}80}81}82} finally {83// Restore the default TimeZone.84TimeZone.setDefault(defaultTimeZone);85}86if (errors > 0) {87throw new RuntimeException("Transition test failed");88}89}90}919293