jdk/test/java/util/TimeZone/Bug6772689.java
author amlu
Fri, 22 Apr 2016 13:01:41 +0800
changeset 37598 cd76e5a8da79
parent 36625 d2e2a8833168
permissions -rw-r--r--
8153933: Remove intermittent key from TimeZone/Bug6772689.java and move back to tier1 Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8523
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
     1
/*
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
     2
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
     4
 *
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
     7
 * published by the Free Software Foundation.
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
     8
 *
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    13
 * accompanied this code).
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    14
 *
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    18
 *
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    21
 * questions.
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    22
 */
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    23
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    24
/*
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    25
 * @test
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    26
 * @bug 6772689
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    27
 * @summary Test for standard-to-daylight transitions at midnight:
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    28
 * date stays on the given day.
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    29
 */
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    30
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    31
import java.util.Calendar;
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    32
import java.util.Date;
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    33
import java.util.GregorianCalendar;
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    34
import java.util.TimeZone;
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    35
import static java.util.GregorianCalendar.*;
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    36
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    37
public class Bug6772689 {
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    38
    private static final int BEGIN_YEAR = 2035;
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    39
    private static final int END_YEAR = BEGIN_YEAR + 28;
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    40
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    41
    public static void main(String[] args) {
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    42
        TimeZone defaultTimeZone = TimeZone.getDefault();
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    43
        int errors = 0;
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    44
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    45
        Calendar cal = new GregorianCalendar(BEGIN_YEAR, MARCH, 1);
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    46
        String[] tzids = TimeZone.getAvailableIDs();
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    47
        try {
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    48
            for (String id : tzids) {
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    49
                TimeZone tz = TimeZone.getTimeZone(id);
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    50
                if (!tz.useDaylightTime()) {
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    51
                    continue;
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    52
                }
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    53
                TimeZone.setDefault(tz);
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    54
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    55
              dateloop:
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    56
                // Use future dates because sun.util.calendar.ZoneInfo
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    57
                // delegates offset transition calculations to a SimpleTimeZone
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    58
                // (after 2038 as of JDK7).
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    59
                for (int year = BEGIN_YEAR; year < END_YEAR; year++) {
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    60
                    for (int month = MARCH; month <= NOVEMBER; month++) {
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    61
                        cal.set(year, month, 1, 15, 0, 0);
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    62
                        int maxDom = cal.getActualMaximum(DAY_OF_MONTH);
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    63
                        for (int dom = 1; dom <= maxDom; dom++) {
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    64
                            Date date = new Date(year - 1900, month, dom);
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    65
                            if (date.getYear()+1900 != year
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    66
                                || date.getMonth() != month
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    67
                                || date.getDate() != dom) {
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    68
                                System.err.printf("%s: got %04d-%02d-%02d, expected %04d-%02d-%02d%n",
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    69
                                                  id,
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    70
                                                  date.getYear() + 1900,
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    71
                                                  date.getMonth() + 1,
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    72
                                                  date.getDate(),
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    73
                                                  year,
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    74
                                                  month + 1,
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    75
                                                  dom);
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    76
                                errors++;
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    77
                                break dateloop;
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    78
                            }
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    79
                        }
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    80
                    }
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    81
                }
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    82
            }
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    83
        } finally {
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    84
            // Restore the default TimeZone.
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    85
            TimeZone.setDefault(defaultTimeZone);
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    86
        }
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    87
        if (errors > 0) {
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    88
            throw new RuntimeException("Transition test failed");
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    89
        }
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    90
    }
864a651f7b53 6772689: java.sql.Date.valueOf("2042-10-xx").toString() wrong in some time zones
okutsu
parents:
diff changeset
    91
}