3187N/A/*
3187N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3187N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3187N/A *
3187N/A * This code is free software; you can redistribute it and/or modify it
3187N/A * under the terms of the GNU General Public License version 2 only, as
3187N/A * published by the Free Software Foundation.
3187N/A *
3187N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3187N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3187N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3187N/A * version 2 for more details (a copy is included in the LICENSE file that
3187N/A * accompanied this code).
3187N/A *
3187N/A * You should have received a copy of the GNU General Public License version
3187N/A * 2 along with this work; if not, write to the Free Software Foundation,
3187N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3187N/A *
3187N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3187N/A * or visit www.oracle.com if you need additional information or have any
3187N/A * questions.
3187N/A */
3187N/A
3187N/A/*
3187N/A * @test
3187N/A * @bug 4396385
3187N/A * @summary Make sure to detect invalid values for 1-based hour formats.
3187N/A */
3187N/A
3187N/Aimport java.text.*;
3187N/Aimport java.util.*;
3187N/A
3187N/Apublic class Bug4396385 {
3187N/A private static int errorCount = 0;
3187N/A private static String[][] data = {
3187N/A { "hh:mma", "-1:30AM" },
3187N/A { "hh:mma", "00:30AM" },
3187N/A { "hh:mma", "13:30AM" },
3187N/A { "kk:mm", "-1:12" },
3187N/A { "kk:mm", "00:12" },
3187N/A { "kk:mm", "25:12" },
3187N/A };
3187N/A
3187N/A public static void main(String[] args) {
3187N/A TimeZone tz = TimeZone.getDefault();
3187N/A // Use "GMT" to avoid any surprises related to offset
3187N/A // transitions.
3187N/A TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
3187N/A
3187N/A try {
3187N/A for (String[] item : data) {
3187N/A test(item[0], item[1]);
3187N/A }
3187N/A } finally {
3187N/A // Restore the default time zone
3187N/A TimeZone.setDefault(tz);
3187N/A }
3187N/A
3187N/A if (errorCount > 0) {
3187N/A throw new RuntimeException("Failed with " + errorCount + " error(s).");
3187N/A }
3187N/A }
3187N/A
3187N/A private static void test(String pattern, String src) {
3187N/A SimpleDateFormat sdf = new SimpleDateFormat(pattern, Locale.US);
3187N/A sdf.setLenient(false);
3187N/A ParsePosition pos = new ParsePosition(0);
3187N/A System.out.printf("parse: \"%s\" with \"%s\"", src, pattern);
3187N/A Date date = sdf.parse(src, pos);
3187N/A System.out.printf(": date = %s, errorIndex = %d", date, pos.getErrorIndex());
3187N/A if (date != null || pos.getErrorIndex() == -1) {
3187N/A System.out.println(": failed");
3187N/A errorCount++;
3187N/A } else {
3187N/A System.out.println(": passed");
3187N/A }
3187N/A }
3187N/A}