Path: blob/master/test/jdk/java/text/Format/DateFormat/Bug6645292.java
41152 views
/*1* Copyright (c) 2008, 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 664529226* @summary Make sure to parse a DST time zone name with which the27* last DST rule doesn't observe DST.28*/2930import java.text.*;31import java.util.*;32import static java.util.Calendar.*;3334public class Bug6645292 {35public static void main(String[] args) {36Locale loc = Locale.getDefault();37TimeZone zone = TimeZone.getDefault();38try {39Locale.setDefault(Locale.US);40// Use "Asia/Shanghai" with an old time stamp rather than41// "Australia/Perth" because if Perth decides to obserb DST42// permanently, that decision will make this test case43// useless. There's the same risk with China, though.44TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));45Calendar cal = Calendar.getInstance();46cal.clear();47cal.set(1986, JUNE, 1);48Date d1 = cal.getTime();49SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss zzzz");50String s = df.format(d1);51Date d2 = null;52try {53d2 = df.parse(s);54} catch (Exception e) {55throw new RuntimeException(e);56}57if (!d1.equals(d2)) {58throw new RuntimeException("d1 (" + d1 + ") != d2 (" + d2 + ")");59}60} finally {61Locale.setDefault(loc);62TimeZone.setDefault(zone);63}64}65}666768