1352N/A/*
2362N/A * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
1352N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1352N/A *
1352N/A * This code is free software; you can redistribute it and/or modify it
1352N/A * under the terms of the GNU General Public License version 2 only, as
1352N/A * published by the Free Software Foundation.
1352N/A *
1352N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1352N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1352N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1352N/A * version 2 for more details (a copy is included in the LICENSE file that
1352N/A * accompanied this code).
1352N/A *
1352N/A * You should have received a copy of the GNU General Public License version
1352N/A * 2 along with this work; if not, write to the Free Software Foundation,
1352N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1352N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1352N/A */
1352N/A
1352N/A/**
1352N/A * @test
1352N/A * @bug 6609750
1352N/A * @summary Make sure that SimpleDateFormat.format() formats years correctly.
1352N/A */
1352N/Aimport java.text.*;
1352N/Aimport java.util.*;
1352N/A
1352N/Apublic class Bug6609750 {
1352N/A
1352N/A public static void main(String[] args) {
1352N/A boolean error = false;
1352N/A
1352N/A Locale defaultLocale = Locale.getDefault();
1352N/A Locale.setDefault(Locale.US);
1352N/A
1352N/A Date[] dates = {
1352N/A new Date(9-1900, Calendar.JUNE, 12),
1352N/A new Date(99-1900, Calendar.JUNE, 12),
1352N/A new Date(999-1900, Calendar.JUNE, 12),
1352N/A new Date(2009-1900, Calendar.JUNE, 12),
1352N/A new Date(30009-1900, Calendar.JUNE, 12),
1352N/A };
1352N/A
1352N/A String[] patterns = {
1352N/A "y", "yy", "yyy", "yyyy", "yyyyy", "yyyyyy"
1352N/A };
1352N/A String[][] expectedResults = {
1352N/A {"9", "09", "009", "0009", "00009", "000009"},
1352N/A {"99", "99", "099", "0099", "00099", "000099"},
1352N/A {"999", "99", "999", "0999", "00999", "000999"},
1352N/A {"2009", "09", "2009", "2009", "02009", "002009"},
1352N/A {"30009", "09", "30009", "30009", "30009", "030009"},
1352N/A };
1352N/A
1352N/A SimpleDateFormat sdf = new SimpleDateFormat();
1352N/A for (int dateNo = 0; dateNo < dates.length; dateNo++) {
1352N/A Date date = dates[dateNo];
1352N/A for (int patternNo = 0; patternNo < patterns.length; patternNo++) {
1352N/A sdf.applyPattern(patterns[patternNo]);
1352N/A String got = sdf.format(date);
1352N/A if (!expectedResults[dateNo][patternNo].equals(got)) {
1352N/A error = true;
1352N/A System.err.println("Failed: Unexpected format result: " +
1352N/A "Expected: \"" + expectedResults[dateNo][patternNo] +
1352N/A "\", Got: \"" + got + "\" for date " + date +
1352N/A " with pattern \"" + patterns[patternNo] + "\"");
1352N/A }
1352N/A }
1352N/A }
1352N/A
1352N/A Locale.setDefault(defaultLocale);
1352N/A if (error) {
1352N/A throw new RuntimeException("SimpleDateFormat.format() error.");
1352N/A };
1352N/A }
1352N/A
1352N/A}