3626N/A/*
3626N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3626N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3626N/A *
3626N/A * This code is free software; you can redistribute it and/or modify it
3626N/A * under the terms of the GNU General Public License version 2 only, as
3626N/A * published by the Free Software Foundation.
3626N/A *
3626N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3626N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3626N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3626N/A * version 2 for more details (a copy is included in the LICENSE file that
3626N/A * accompanied this code).
3626N/A *
3626N/A * You should have received a copy of the GNU General Public License version
3626N/A * 2 along with this work; if not, write to the Free Software Foundation,
3626N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3626N/A *
3626N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3626N/A * or visit www.oracle.com if you need additional information or have any
3626N/A * questions.
3626N/A */
3626N/A
3626N/A/*
3626N/A * @test
3626N/A * @bug 6772689
3626N/A * @summary Test for standard-to-daylight transitions at midnight:
3626N/A * date stays on the given day.
3626N/A */
3626N/A
3626N/Aimport java.util.Calendar;
3626N/Aimport java.util.Date;
3626N/Aimport java.util.GregorianCalendar;
3626N/Aimport java.util.TimeZone;
3626N/Aimport static java.util.GregorianCalendar.*;
3626N/A
3626N/Apublic class Bug6772689 {
3626N/A private static final int BEGIN_YEAR = 2035;
3626N/A private static final int END_YEAR = BEGIN_YEAR + 28;
3626N/A
3626N/A public static void main(String[] args) {
3626N/A TimeZone defaultTimeZone = TimeZone.getDefault();
3626N/A int errors = 0;
3626N/A
3626N/A Calendar cal = new GregorianCalendar(BEGIN_YEAR, MARCH, 1);
3626N/A String[] tzids = TimeZone.getAvailableIDs();
3626N/A try {
3626N/A for (String id : tzids) {
3626N/A TimeZone tz = TimeZone.getTimeZone(id);
3626N/A if (!tz.useDaylightTime()) {
3626N/A continue;
3626N/A }
3626N/A TimeZone.setDefault(tz);
3626N/A
3626N/A dateloop:
3626N/A // Use future dates because sun.util.calendar.ZoneInfo
3626N/A // delegates offset transition calculations to a SimpleTimeZone
3626N/A // (after 2038 as of JDK7).
3626N/A for (int year = BEGIN_YEAR; year < END_YEAR; year++) {
3626N/A for (int month = MARCH; month <= NOVEMBER; month++) {
3626N/A cal.set(year, month, 1, 15, 0, 0);
3626N/A int maxDom = cal.getActualMaximum(DAY_OF_MONTH);
3626N/A for (int dom = 1; dom <= maxDom; dom++) {
3626N/A Date date = new Date(year - 1900, month, dom);
3626N/A if (date.getYear()+1900 != year
3626N/A || date.getMonth() != month
3626N/A || date.getDate() != dom) {
3626N/A System.err.printf("%s: got %04d-%02d-%02d, expected %04d-%02d-%02d%n",
3626N/A id,
3626N/A date.getYear() + 1900,
3626N/A date.getMonth() + 1,
3626N/A date.getDate(),
3626N/A year,
3626N/A month + 1,
3626N/A dom);
3626N/A errors++;
3626N/A break dateloop;
3626N/A }
3626N/A }
3626N/A }
3626N/A }
3626N/A }
3626N/A } finally {
3626N/A // Restore the default TimeZone.
3626N/A TimeZone.setDefault(defaultTimeZone);
3626N/A }
3626N/A if (errors > 0) {
3626N/A throw new RuntimeException("Transition test failed");
3626N/A }
3626N/A }
3626N/A}