1 /* 2 * Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 4845901 27 * @summary Make sure that SimpleDateFormat.parse() can distinguish 28 * the same time zone abbreviation for standard and daylight saving 29 * time. 30 */ 31 32 import java.util.*; 33 import java.text.SimpleDateFormat; 34 35 public class Bug4845901 { 36 public static void main (String args[]) { 37 TimeZone savedTZ = TimeZone.getDefault(); 38 TimeZone.setDefault(TimeZone.getTimeZone("Australia/Sydney")); 39 SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss.SSS z"); 40 try { 41 testParse(sdf, "2003.01.13 11:10:00.802 AEDT", 11); 42 testParse(sdf, "2003.06.12 11:10:00.802 AEST", 11); 43 testParse(sdf, "2004.12.24 10:10:00.002 AEDT", 10); 44 testParse(sdf, "2004.08.10 10:10:00.002 AEST", 10); 45 } finally { 46 TimeZone.setDefault(savedTZ); 47 } 48 } 49 50 static void testParse(SimpleDateFormat sdf, String str, int expectedHour) { 51 try { 52 Date parsedDate = sdf.parse(str); 53 if (parsedDate.getHours() != expectedHour) { 54 throw new RuntimeException( 55 "parsed date has wrong hour: " + parsedDate.getHours() 56 + ", expected: " + expectedHour 57 + "\ngiven string: " + str 58 + "\nparsedDate = " + parsedDate); 59 } 60 } catch (java.text.ParseException e) { 61 throw new RuntimeException("parse exception", e); 62 } 63 } 64 }