Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/text/Format/DateFormat/bug4097450.java
41152 views
1
/*
2
* Copyright (c) 1998, 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
*
27
* @bug 4097450
28
*/
29
30
import java.text.DateFormat;
31
import java.text.ParseException;
32
import java.text.SimpleDateFormat;
33
34
public class bug4097450
35
{
36
public static void main(String args[])
37
{
38
//
39
// Date parse requiring 4 digit year.
40
//
41
String[] dstring = {"97","1997", "97","1997","01","2001", "01","2001"
42
, "1",
43
"1","11", "11","111", "111"};
44
String[] dformat = {"yy", "yy","yyyy","yyyy","yy", "yy","yyyy","yyyy"
45
,
46
"yy","yyyy","yy","yyyy", "yy","yyyy"};
47
boolean[] dresult = {true, false, false, true,true, false, false, true
48
,false,
49
false,true, false,false, false};
50
SimpleDateFormat formatter;
51
SimpleDateFormat resultFormatter = new SimpleDateFormat("yyyy");
52
53
System.out.println("Format\tSource\tResult");
54
System.out.println("-------\t-------\t-------");
55
for (int i = 0; i < dstring.length; i++)
56
{
57
System.out.print(dformat[i] + "\t" + dstring[i] + "\t");
58
formatter = new SimpleDateFormat(dformat[i]);
59
try {
60
System.out.print(resultFormatter.format(formatter.parse(dstring[
61
i])));
62
//if ( !dresult[i] ) System.out.print(" <-- error!");
63
}
64
catch (ParseException exception) {
65
//if ( dresult[i] ) System.out.print(" <-- error!");
66
System.out.print("exception --> " + exception);
67
}
68
System.out.println();
69
}
70
}
71
}
72
73