Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/text/Format/DateFormat/bug4358730.java
41152 views
1
/*
2
* Copyright (c) 2000, 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
import java.io.*;
25
import java.util.*;
26
import java.text.*;
27
28
/**
29
* @test
30
* @bug 4358730
31
* @library /java/text/testlib
32
* @summary test that confirms Zero-Padding on year.
33
*/
34
35
public class bug4358730 extends IntlTest {
36
37
public static void main(String[] args) throws Exception {
38
new bug4358730().run(args);
39
}
40
41
String[] patterns = {"y", "yy", "yyy", "yyyy", "yyyyy"};
42
String[][] data = {
43
/* 2 A.D. */ {"2", "02", "002", "0002", "00002"},
44
/* 20 A.D. */ {"20", "20", "020", "0020", "00020"},
45
/* 200 A.D. */ {"200", "00", "200", "0200", "00200"},
46
/* 2000 A.D. */ {"2000", "00", "2000", "2000", "02000"},
47
};
48
int[] year = {2, 20, 200, 2000};
49
50
int datasize = data.length;
51
int nPatterns = data[0].length;
52
53
public void Test4358730() {
54
TimeZone saveZone = TimeZone.getDefault();
55
Locale saveLocale = Locale.getDefault();
56
57
try {
58
TimeZone.setDefault(TimeZone.getTimeZone("PST"));
59
Locale.setDefault(new Locale("en", "US"));
60
SimpleDateFormat sdf = new SimpleDateFormat();
61
62
for (int i = 0; i < datasize; i++) {
63
@SuppressWarnings("deprecation")
64
Date d = new Date(year[i]-1900, 10, 15);
65
for (int j = 0; j < nPatterns; j++) {
66
sdf.applyPattern(patterns[j]);
67
if (!data[i][j].equals(sdf.format(d))) {
68
errln("Invalid format : " + sdf.format(d) +
69
", expected : " + data[i][j]);
70
}
71
}
72
}
73
}
74
finally {
75
TimeZone.setDefault(saveZone);
76
Locale.setDefault(saveLocale);
77
}
78
}
79
}
80
81