Path: blob/master/test/jdk/java/text/Format/DateFormat/Bug6530336.java
41152 views
/*1* Copyright (c) 2007, 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 6530336 6537997 800857726* @library /java/text/testlib27* @run main/othervm -Djava.locale.providers=COMPAT,SPI Bug653033628*/2930import java.text.SimpleDateFormat;31import java.util.Calendar;32import java.util.Date;33import java.util.Locale;34import java.util.TimeZone;3536public class Bug6530336 {3738public static void main(String[] args) throws Exception {39Locale defaultLocale = Locale.getDefault();40TimeZone defaultTimeZone = TimeZone.getDefault();4142boolean err = false;4344try {45Locale locales[] = Locale.getAvailableLocales();46TimeZone timezone_LA = TimeZone.getTimeZone("America/Los_Angeles");47TimeZone.setDefault(timezone_LA);4849TimeZone timezones[] = {50TimeZone.getTimeZone("America/New_York"),51TimeZone.getTimeZone("America/Denver"),52};5354String[] expected = {55"Sun Jul 15 12:00:00 PDT 2007",56"Sun Jul 15 14:00:00 PDT 2007",57};5859Date[] dates = new Date[2];6061for (int i = 0; i < locales.length; i++) {62Locale locale = locales[i];63if (!TestUtils.usesGregorianCalendar(locale)) {64continue;65}6667Locale.setDefault(locale);6869for (int j = 0; j < timezones.length; j++) {70Calendar cal = Calendar.getInstance(timezones[j]);71cal.set(2007, 6, 15, 15, 0, 0);72dates[j] = cal.getTime();73}7475SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");7677for (int j = 0; j < timezones.length; j++) {78sdf.setTimeZone(timezones[j]);79String date = sdf.format(dates[j]);80sdf.setTimeZone(timezone_LA);81String date_LA = sdf.parse(date).toString();8283if (!expected[j].equals(date_LA)) {84System.err.println("Got wrong Pacific time (" +85date_LA + ") for (" + date + ") in " + locale +86" in " + timezones[j] +87".\nExpected=" + expected[j]);88err = true;89}90}91}92}93catch (Exception e) {94e.printStackTrace();95err = true;96}97finally {98Locale.setDefault(defaultLocale);99TimeZone.setDefault(defaultTimeZone);100101if (err) {102throw new RuntimeException("Failed.");103}104}105}106107}108109110