-
-
Notifications
You must be signed in to change notification settings - Fork 314
/
FormatTest_zh_tw.java
147 lines (133 loc) · 5.4 KB
/
FormatTest_zh_tw.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*******************************************************************************
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
import org.junit.*;
import static org.junit.Assert.*;
import java.time.*;
import java.time.format.*;
import java.util.*;
public class FormatTest_zh_tw{
private long version = 0L;
@Before
public void init() {
version = JavaVersion.getVersion();
}
@Test
public void WeekOfDayTest(){
LocalDate date = LocalDate.of(2013, 4, 30);
String str;
str = date.format(DateTimeFormatter.ofPattern(
"E EE EEE EEEE EEEEE",
Locale.TRADITIONAL_CHINESE));
assertEquals("\u9031\u4e8c \u9031\u4e8c \u9031\u4e8c \u661f\u671f\u4e8c \u4e8c", str);
str = date.format(DateTimeFormatter.ofPattern(
"e ee eee eeee eeeee",
Locale.TRADITIONAL_CHINESE));
assertEquals("3 03 \u9031\u4e8c \u661f\u671f\u4e8c \u4e8c", str);
try{
str = date.format(DateTimeFormatter.ofPattern(
"cc", Locale.TRADITIONAL_CHINESE));
fail("cc is not supported. It should be c, ccc, cccc, ccccc");
}catch(IllegalArgumentException e){
}
str = date.format(DateTimeFormatter.ofPattern(
"c ccc cccc ccccc",
Locale.TRADITIONAL_CHINESE));
assertEquals("3 \u9031\u4e8c \u661f\u671f\u4e8c \u4e8c", str);
/*
date = LocalDate.of(2014, 3, 16);
for (int i=0;i<7;i++) {
str = date.format(DateTimeFormatter.ofPattern(
//"ccccc",
"M/d (E) c ccc cccc ccccc",
Locale.TRADITIONAL_CHINESE));
System.out.println(str);
String expected = new Integer(i+1).toString();
//assertEquals(expected, str);
date = date.plusDays(1);
}
*/
}
@Test
public void AlignedWeekOfDayTest(){
LocalDate date = LocalDate.of(2014, 3, 16);
String str;
try{
str = date.format(DateTimeFormatter.ofPattern(
"FF",
Locale.TRADITIONAL_CHINESE));
fail("F simbol should be single.");
}catch(IllegalArgumentException e){
}
/*
date = LocalDate.of(2014, 3, 1);
for (int i=0;i<31;i++) {
str = date.format(DateTimeFormatter.ofPattern(
"M/d (E) F",
Locale.TRADITIONAL_CHINESE));
System.out.println(str);
date = date.plusDays(1);
}
*/
date = LocalDate.of(2014, 3, 1);
boolean isJdk19orUp = JavaVersion.getVersion() >= 19_000_000L;
for (int i=0;i<31;i++) {
str = date.format(DateTimeFormatter.ofPattern(
"F",
Locale.TRADITIONAL_CHINESE));
String expect;
// Specification was changed by JDK-8282081
int v = isJdk19orUp
? i/7+1 // Mar/1~7=1, Mar/8~14=2,...
: i%7+1; // Mar/1=1, Mar/2=2,...Mar/8=1,...
String expected = Integer.valueOf(v).toString();
assertEquals(expected, str);
date = date.plusDays(1);
}
}
@Test
public void QuarterTest(){
LocalDate date = LocalDate.of(2014, 3, 17);
String str;
str = date.format(DateTimeFormatter.ofPattern(
"Q QQ QQQ QQQQ QQQQQ",
Locale.TRADITIONAL_CHINESE));
// Not sure about no QuarterAbbreviations case.
// assertEquals("1 01 1 \u7b2c1\u5b63 1", str);
// or
// assertEquals("1 01 \u7b2c1\u5b63 \u7b2c1\u5b63 1", str);
// ?
str = date.format(DateTimeFormatter.ofPattern(
"q qq qqq qqqq qqqqq",
Locale.TRADITIONAL_CHINESE));
if (11_000_000L <= version && version < 13_000_000L) {
assertEquals("1 01 1 \u7b2c1\u5b63 1", str);
} else if (version >= 13_000_000L) {
//Updated by JDK-8221432: Upgrade CLDR to Version 35.1
assertEquals("1 01 \u7b2c1\u5b63 \u7b2c1\u5b63 1", str);
}
}
@Test
public void MonthTest(){
LocalDate date = LocalDate.of(2014, 3, 17);
String str;
str = date.format(DateTimeFormatter.ofPattern(
"M MM MMM MMMM MMMMM",
Locale.TRADITIONAL_CHINESE));
assertEquals("3 03 3\u6708 3\u6708 3", str);
str = date.format(DateTimeFormatter.ofPattern(
"L LL LLL LLLL LLLLL",
Locale.TRADITIONAL_CHINESE));
assertEquals("3 03 3\u6708 3\u6708 3", str);
}
}