jdk/test/java/text/Format/DateFormat/Bug7177315.java
changeset 18146 47760e45a1dd
equal deleted inserted replaced
18145:39484c6a0c61 18146:47760e45a1dd
       
     1 /*
       
     2  * Copyright (c) 2013, 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 7177315
       
    27  * @summary Make sure that space characters are properly skipped when
       
    28  *          parsing 2-digit year values.
       
    29  */
       
    30 
       
    31 import java.text.*;
       
    32 import java.util.*;
       
    33 
       
    34 public class Bug7177315 {
       
    35     private static final String EXPECTED = "01/01/2012";
       
    36     private static final String[] DATA = {
       
    37         "01/01/12",
       
    38         "01/01/ 12",
       
    39         "01/01/       12",
       
    40         "1/1/12",
       
    41         "1/1/  12"
       
    42     };
       
    43 
       
    44     public static void main (String[] args) throws ParseException {
       
    45         SimpleDateFormat parseFormat = new SimpleDateFormat("MM/dd/yy", Locale.US);
       
    46         Calendar cal = new GregorianCalendar(2012-80, Calendar.JANUARY, 1);
       
    47         parseFormat.set2DigitYearStart(cal.getTime());
       
    48         SimpleDateFormat fmtFormat = new SimpleDateFormat("MM/dd/yyyy", Locale.US);
       
    49 
       
    50         for (String text : DATA) {
       
    51             Date date = parseFormat.parse(text);
       
    52             String got = fmtFormat.format(date);
       
    53             if (!EXPECTED.equals(got)) {
       
    54                 throw new RuntimeException("got: " + got + ", expected: " + EXPECTED);
       
    55             }
       
    56         }
       
    57     }
       
    58 }