author | okutsu |
Fri, 07 Jun 2013 17:07:12 +0900 | |
changeset 18146 | 47760e45a1dd |
permissions | -rw-r--r-- |
18146
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
1 |
/* |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
4 |
* |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
8 |
* |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
13 |
* accompanied this code). |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
14 |
* |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
18 |
* |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
21 |
* questions. |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
22 |
*/ |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
23 |
|
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
24 |
/** |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
25 |
* @test |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
26 |
* @bug 7177315 |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
27 |
* @summary Make sure that space characters are properly skipped when |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
28 |
* parsing 2-digit year values. |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
29 |
*/ |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
30 |
|
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
31 |
import java.text.*; |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
32 |
import java.util.*; |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
33 |
|
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
34 |
public class Bug7177315 { |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
35 |
private static final String EXPECTED = "01/01/2012"; |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
36 |
private static final String[] DATA = { |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
37 |
"01/01/12", |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
38 |
"01/01/ 12", |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
39 |
"01/01/ 12", |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
40 |
"1/1/12", |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
41 |
"1/1/ 12" |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
42 |
}; |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
43 |
|
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
44 |
public static void main (String[] args) throws ParseException { |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
45 |
SimpleDateFormat parseFormat = new SimpleDateFormat("MM/dd/yy", Locale.US); |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
46 |
Calendar cal = new GregorianCalendar(2012-80, Calendar.JANUARY, 1); |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
47 |
parseFormat.set2DigitYearStart(cal.getTime()); |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
48 |
SimpleDateFormat fmtFormat = new SimpleDateFormat("MM/dd/yyyy", Locale.US); |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
49 |
|
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
50 |
for (String text : DATA) { |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
51 |
Date date = parseFormat.parse(text); |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
52 |
String got = fmtFormat.format(date); |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
53 |
if (!EXPECTED.equals(got)) { |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
54 |
throw new RuntimeException("got: " + got + ", expected: " + EXPECTED); |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
55 |
} |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
56 |
} |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
57 |
} |
47760e45a1dd
7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents:
diff
changeset
|
58 |
} |