Debian Codegraph @

js/src/tests/non262/Intl/DateTimeFormat/era.js

raw
1 // |reftest| skip-if(!this.hasOwnProperty("Intl"))
2
3 const {
4 Era, Year, Month, Day, Literal
5 } = DateTimeFormatParts;
6
7 const tests = {
8 "en": [
9 {
10 options: {
11 day: "numeric",
12 month: "numeric",
13 year: "numeric",
14 era: "short",
15 timeZone: "UTC",
16 },
17 dates: [
18 {
19 date: new Date("1970-01-01T00:00:00.000Z"),
20 parts: [
21 Month("1"), Literal("/"), Day("1"), Literal("/"), Year("1970"), Literal(" "), Era("AD")
22 ],
23 },
24 {
25 date: new Date("-001970-01-01T00:00:00.000Z"),
26 parts: [
27 Month("1"), Literal("/"), Day("1"), Literal("/"), Year("1971"), Literal(" "), Era("BC")
28 ],
29 },
30 ],
31 },
32 ],
33 "en-001": [
34 {
35 options: {
36 day: "numeric",
37 month: "numeric",
38 year: "numeric",
39 era: "short",
40 timeZone: "UTC",
41 },
42 dates: [
43 {
44 date: new Date("1970-01-01T00:00:00.000Z"),
45 parts: [
46 Day("1"), Literal("/"), Month("1"), Literal("/"), Year("1970"), Literal(" "), Era("AD")
47 ],
48 },
49 {
50 date: new Date("-001970-01-01T00:00:00.000Z"),
51 parts: [
52 Day("1"), Literal("/"), Month("1"), Literal("/"), Year("1971"), Literal(" "), Era("BC")
53 ],
54 },
55 ],
56 },
57 ],
58 "de": [
59 {
60 options: {
61 day: "numeric",
62 month: "numeric",
63 year: "numeric",
64 era: "short",
65 timeZone: "UTC",
66 },
67 dates: [
68 {
69 date: new Date("1970-01-01T00:00:00.000Z"),
70 parts: [
71 Day("01"), Literal("."), Month("01"), Literal("."), Year("1970"), Literal(" "), Era("n. Chr.")
72 ],
73 },
74 {
75 date: new Date("-001970-01-01T00:00:00.000Z"),
76 parts: [
77 Day("01"), Literal("."), Month("01"), Literal("."), Year("1971"), Literal(" "), Era("v. Chr.")
78 ],
79 },
80 ],
81 },
82 ],
83 "fr": [
84 {
85 options: {
86 day: "numeric",
87 month: "numeric",
88 year: "numeric",
89 era: "short",
90 timeZone: "UTC",
91 },
92 dates: [
93 {
94 date: new Date("1970-01-01T00:00:00.000Z"),
95 parts: [
96 Day("01"), Literal("/"), Month("01"), Literal("/"), Year("1970"), Literal(" "), Era("ap. J.-C.")
97 ],
98 },
99 {
100 date: new Date("-001970-01-01T00:00:00.000Z"),
101 parts: [
102 Day("01"), Literal("/"), Month("01"), Literal("/"), Year("1971"), Literal(" "), Era("av. J.-C.")
103 ],
104 },
105 ],
106 },
107 ],
108 "es": [
109 {
110 options: {
111 day: "numeric",
112 month: "numeric",
113 year: "numeric",
114 era: "short",
115 timeZone: "UTC",
116 },
117 dates: [
118 {
119 date: new Date("1970-01-01T00:00:00.000Z"),
120 parts: [
121 Day("1"), Literal("/"), Month("1"), Literal("/"), Year("1970"), Literal(" "), Era("d. C.")
122 ],
123 },
124 {
125 date: new Date("-001970-01-01T00:00:00.000Z"),
126 parts: [
127 Day("1"), Literal("/"), Month("1"), Literal("/"), Year("1971"), Literal(" "), Era("a. C.")
128 ],
129 },
130 ],
131 },
132 ],
133 "nl": [
134 {
135 options: {
136 day: "numeric",
137 month: "numeric",
138 year: "numeric",
139 era: "short",
140 timeZone: "UTC",
141 },
142 dates: [
143 {
144 date: new Date("1970-01-01T00:00:00.000Z"),
145 parts: [
146 Day("1"), Literal("/"), Month("1"), Literal("/"), Year("1970"), Literal(" "), Era("n.Chr.")
147 ],
148 },
149 {
150 date: new Date("-001970-01-01T00:00:00.000Z"),
151 parts: [
152 Day("1"), Literal("/"), Month("1"), Literal("/"), Year("1971"), Literal(" "), Era("v.Chr.")
153 ],
154 },
155 ],
156 },
157 ],
158 "ja": [
159 {
160 options: {
161 day: "numeric",
162 month: "numeric",
163 year: "numeric",
164 era: "short",
165 timeZone: "UTC",
166 },
167 dates: [
168 {
169 date: new Date("1970-01-01T00:00:00.000Z"),
170 parts: [
171 Era("西暦"), Year("1970"), Literal("/"), Month("1"), Literal("/"), Day("1")
172 ],
173 },
174 {
175 date: new Date("-001970-01-01T00:00:00.000Z"),
176 parts: [
177 Era("紀元前"), Year("1971"), Literal("/"), Month("1"), Literal("/"), Day("1")
178 ],
179 },
180 ],
181 },
182 ],
183 "zh": [
184 {
185 options: {
186 day: "numeric",
187 month: "numeric",
188 year: "numeric",
189 era: "short",
190 timeZone: "UTC",
191 },
192 dates: [
193 {
194 date: new Date("1970-01-01T00:00:00.000Z"),
195 parts: [
196 Era("公元"), Literal(" "), Year("1970"), Literal("-"), Month("01"), Literal("-"), Day("01")
197 ],
198 },
199 {
200 date: new Date("-001970-01-01T00:00:00.000Z"),
201 parts: [
202 Era("公元前"), Literal(" "), Year("1971"), Literal("-"), Month("01"), Literal("-"), Day("01")
203 ],
204 },
205 ],
206 },
207 ],
208 "ar-EG": [
209 {
210 options: {
211 day: "numeric",
212 month: "numeric",
213 year: "numeric",
214 era: "short",
215 timeZone: "UTC",
216 },
217 dates: [
218 {
219 date: new Date("1970-01-01T00:00:00.000Z"),
220 parts: [
221 Day("٠١"), Literal("-"), Month("٠١"), Literal("-"), Year("١٩٧٠"), Literal(" "), Era("م")
222 ],
223 },
224 {
225 date: new Date("-001970-01-01T00:00:00.000Z"),
226 parts: [
227 Day("٠١"), Literal("-"), Month("٠١"), Literal("-"), Year("١٩٧١"), Literal(" "), Era("ق.م")
228 ],
229 },
230 ],
231 },
232 ],
233 };
234
235 for (let [locale, inputs] of Object.entries(tests)) {
236 for (let {options, dates} of inputs) {
237 let dtf = new Intl.DateTimeFormat(locale, options);
238 for (let {date, parts} of dates) {
239 assertParts(dtf, date, parts);
240 }
241 }
242 }
243
244 if (typeof reportCompare === "function")
245 reportCompare(0, 0, "ok");