Debian Codegraph @

js/src/tests/non262/Intl/DateTimeFormat/related-year.js

raw
1 // |reftest| skip-if(!this.hasOwnProperty("Intl"))
2
3 const {
4 Era, Year, YearName, RelatedYear, Month, Day, Literal
5 } = DateTimeFormatParts
6
7 const tests = [
8 // Test with non-leap month.
9 {
10 date: new Date("2020-04-23T00:00:00Z"),
11 options: {},
12 calendar: "chinese",
13 locales: {
14 "en": [Month("4"), Literal("/"), Day("1"), Literal("/"), RelatedYear("2020")],
15 "de": [Day("1"), Literal("."), Month("4"), Literal("."), Year("37")],
16 "ja": [YearName("庚子"), Literal("-"), Month("4"), Literal("-"), Day("1")],
17 "zh": [RelatedYear("2020"), Literal("年"), Month("四月"), Day("1")],
18 "ar-EG": [RelatedYear("٢٠٢٠"), Literal("-"), Month("٠٤"), Literal("-"), Day("٠١")],
19 }
20 },
21
22 // Test with leap month.
23 {
24 date: new Date("2020-05-23T00:00:00Z"),
25 options: {},
26 calendar: "chinese",
27 locales: {
28 "en": [Month("4bis"), Literal("/"), Day("1"), Literal("/"), RelatedYear("2020")],
29 "de": [Day("1"), Literal("."), Month("4bis"), Literal("."), Year("37")],
30 "ja": [YearName("庚子"), Literal("-"), Month("閏4"), Literal("-"), Day("1")],
31 "zh": [RelatedYear("2020"), Literal("年"), Month("闰四月"), Day("1")],
32 "ar-EG": [RelatedYear("٢٠٢٠"), Literal("-"), Month("٠٤bis"), Literal("-"), Day("٠١")],
33 }
34 },
35
36 // Display only "year" field.
37 {
38 date: new Date("2020-04-23T00:00:00Z"),
39 options: {year: "numeric"},
40 calendar: "chinese",
41 locales: {
42 "en": [RelatedYear("2020"), Literal("("), YearName("geng-zi"), Literal(")")],
43 "de": [YearName("geng-zi")],
44 "ja": [YearName("庚子"), Literal("年")],
45 "zh": [RelatedYear("2020"), YearName("庚子"), Literal("年")],
46 "ar-EG": [RelatedYear("٢٠٢٠"), Literal("("), YearName("geng-zi"), Literal(")")],
47 }
48 },
49
50 // Display only "month" field.
51 {
52 date: new Date("2020-04-23T00:00:00Z"),
53 options: {month: "long"},
54 calendar: "chinese",
55 locales: {
56 "en": [Month("Fourth Month")],
57 "de": [Month("M04")],
58 "ja": [Month("四月")],
59 "zh": [Month("四月")],
60 "ar-EG": [Month("M04")],
61 }
62 },
63
64 // Display only "month" field. (Leap month)
65 {
66 date: new Date("2020-05-23T00:00:00Z"),
67 options: {month: "long"},
68 calendar: "chinese",
69 locales: {
70 "en": [Month("Fourth Monthbis")],
71 "de": [Month("M04bis")],
72 "ja": [Month("閏四月")],
73 "zh": [Month("闰四月")],
74 "ar-EG": [Month("M04bis")],
75 }
76 },
77
78 // Display "year" and "month" fields.
79 {
80 date: new Date("2020-04-23T00:00:00Z"),
81 options: {year: "numeric", month: "long"},
82 calendar: "chinese",
83 locales: {
84 "en": [Month("Fourth Month"), Literal(" "), RelatedYear("2020"), Literal("("), YearName("geng-zi"), Literal(")")],
85 "de": [Month("M04"), Literal(" "), YearName("geng-zi")],
86 "ja": [YearName("庚子"), Literal("年"), Month("四月")],
87 "zh": [RelatedYear("2020"), YearName("庚子"), Literal("年"), Month("四月")],
88 "ar-EG": [RelatedYear("٢٠٢٠"), Literal("("), YearName("geng-zi"), Literal(") "), Month("M04")],
89 }
90 },
91
92 // Display "year" and "month" fields. (Leap month)
93 {
94 date: new Date("2020-05-23T00:00:00Z"),
95 options: {year: "numeric", month: "long"},
96 calendar: "chinese",
97 locales: {
98 "en": [Month("Fourth Monthbis"), Literal(" "), RelatedYear("2020"), Literal("("), YearName("geng-zi"), Literal(")")],
99 "de": [Month("M04bis"), Literal(" "), YearName("geng-zi")],
100 "ja": [YearName("庚子"), Literal("年"), Month("閏四月")],
101 "zh": [RelatedYear("2020"), YearName("庚子"), Literal("年"), Month("闰四月")],
102 "ar-EG": [RelatedYear("٢٠٢٠"), Literal("("), YearName("geng-zi"), Literal(") "), Month("M04bis")],
103 }
104 },
105
106 // Related year in traditional Korean calendar.
107 {
108 date: new Date("2019-01-01T00:00:00Z"),
109 options: {},
110 calendar: "dangi",
111 locales: {
112 "en": [Month("11"), Literal("/"), Day("26"), Literal("/"), RelatedYear("2018")],
113 "ko": [RelatedYear("2018"), Literal(". "), Month("11"), Literal(". "), Day("26"), Literal(".")],
114 }
115 },
116
117 // Allowing the calendar to modify the pattern selection choice can result in falling back to
118 // the root locale patterns in more cases. That can result in displaying the era field by
119 // default, among other things.
120 {
121 date: new Date("2019-01-01T00:00:00Z"),
122 options: {},
123 calendar: "buddhist",
124 locales: {
125 "en": [Month("1"), Literal("/"), Day("1"), Literal("/"), Year("2562"), Literal(" "), Era("BE")],
126 "th": [Day("1"), Literal("/"), Month("1"), Literal("/"), Year("2562")],
127 }
128 },
129 {
130 date: new Date("2019-01-01T00:00:00Z"),
131 options: {},
132 calendar: "hebrew",
133 locales: {
134 "en": [Day("24"), Literal(" "), Month("Tevet"), Literal(" "), Year("5779")],
135 "he": [Day("24"), Literal(" ב"), Month("טבת"), Literal(" "), Year("5779")],
136 "fr": [Day("24"), Literal("/"), Month("04"), Literal("/"), Year("5779"), Literal(" "), Era("A. M.")],
137 }
138 },
139 {
140 date: new Date("2019-01-01T00:00:00Z"),
141 options: {},
142 calendar: "islamic",
143 locales: {
144 "en": [Month("4"), Literal("/"), Day("25"), Literal("/"), Year("1440"), Literal(" "), Era("AH")],
145 "ar-EG": [Day("٢٥"), Literal("\u200F/"), Month("٤"), Literal("\u200F/"), Year("١٤٤٠"), Literal(" "), Era("هـ")],
146 }
147 },
148 {
149 date: new Date("2019-01-01T00:00:00Z"),
150 options: {},
151 calendar: "japanese",
152 locales: {
153 "en": [Month("1"), Literal("/"), Day("1"), Literal("/"), Year("31"), Literal(" "), Era("H")],
154 "ja": [Era("H"), Year("31"), Literal("/"), Month("1"), Literal("/"), Day("1")],
155 }
156 },
157 {
158 date: new Date("2019-01-01T00:00:00Z"),
159 options: {},
160 calendar: "persian",
161 locales: {
162 "en": [Month("10"), Literal("/"), Day("11"), Literal("/"), Year("1397"), Literal(" "), Era("AP")],
163 "fa": [Year("۱۳۹۷"), Literal("/"), Month("۱۰"), Literal("/"), Day("۱۱")],
164 }
165 },
166 {
167 date: new Date("2019-01-01T00:00:00Z"),
168 options: {},
169 calendar: "roc",
170 locales: {
171 "en": [Month("1"), Literal("/"), Day("1"), Literal("/"), Year("108"), Literal(" "), Era("Minguo")],
172 "zh-Hant-TW": [Era("民國"), Year("108"), Literal("/"), Month("1"), Literal("/"), Day("1")],
173 }
174 },
175 ];
176
177 for (let {date, options, calendar, locales} of tests) {
178 for (let [locale, result] of Object.entries(locales)) {
179 let df = new Intl.DateTimeFormat(`${locale}-u-ca-${calendar}`, {timeZone: "UTC", ...options});
180 assertParts(df, date, result);
181 }
182 }
183
184 if (typeof reportCompare === "function")
185 reportCompare(0, 0, "ok");