summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Intl/DateTimeFormat/related-year.js
blob: 296de04883a7676e687d86e90345be617bc139fe (plain)
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// |reftest| skip-if(!this.hasOwnProperty("Intl"))

const {
    Era, Year, YearName, RelatedYear, Month, Day, Literal
} = DateTimeFormatParts

const tests = [
    // Test with non-leap month.
    {
        date: new Date("2020-04-23T00:00:00Z"),
        options: {},
        calendar: "chinese",
        locales: {
            "en": [Month("4"), Literal("/"), Day("1"), Literal("/"), RelatedYear("2020")],
            "de": [Day("1"), Literal("."), Month("4"), Literal("."), Year("37")],
            "ja": [YearName("庚子"), Literal("-"), Month("4"), Literal("-"), Day("1")],
            "zh": [RelatedYear("2020"), Literal("年"), Month("四月"), Day("1")],
            "ar": [RelatedYear("٢٠٢٠"), Literal("-"), Month("٠٤"), Literal("-"), Day("٠١")],
        }
    },

    // Test with leap month.
    {
        date: new Date("2020-05-23T00:00:00Z"),
        options: {},
        calendar: "chinese",
        locales: {
            "en": [Month("4bis"), Literal("/"), Day("1"), Literal("/"), RelatedYear("2020")],
            "de": [Day("1"), Literal("."), Month("4bis"), Literal("."), Year("37")],
            "ja": [YearName("庚子"), Literal("-"), Month("閏4"), Literal("-"), Day("1")],
            "zh": [RelatedYear("2020"), Literal("年"), Month("闰四月"), Day("1")],
            "ar": [RelatedYear("٢٠٢٠"), Literal("-"), Month("٠٤bis"), Literal("-"), Day("٠١")],
        }
    },

    // Display only "year" field.
    {
        date: new Date("2020-04-23T00:00:00Z"),
        options: {year: "numeric"},
        calendar: "chinese",
        locales: {
            "en": [RelatedYear("2020"), Literal("("), YearName("geng-zi"), Literal(")")],
            "de": [YearName("geng-zi")],
            "ja": [YearName("庚子"), Literal("年")],
            "zh": [RelatedYear("2020"), YearName("庚子"), Literal("年")],
            "ar": [Year("٣٧")],
        }
    },

    // Display only "month" field.
    {
        date: new Date("2020-04-23T00:00:00Z"),
        options: {month: "long"},
        calendar: "chinese",
        locales: {
            "en": [Month("Fourth Month")],
            "de": [Month("M04")],
            "ja": [Month("四月")],
            "zh": [Month("四月")],
            "ar": [Month("M04")],
        }
    },

    // Display only "month" field. (Leap month)
    {
        date: new Date("2020-05-23T00:00:00Z"),
        options: {month: "long"},
        calendar: "chinese",
        locales: {
            "en": [Month("Fourth Monthbis")],
            "de": [Month("M04bis")],
            "ja": [Month("閏四月")],
            "zh": [Month("闰四月")],
            "ar": [Month("M04bis")],
        }
    },

    // Display "year" and "month" fields.
    {
        date: new Date("2020-04-23T00:00:00Z"),
        options: {year: "numeric", month: "long"},
        calendar: "chinese",
        locales: {
            "en": [Month("Fourth Month"), Literal(" "), RelatedYear("2020"), Literal("("), YearName("geng-zi"), Literal(")")],
            "de": [Month("M04"), Literal(" "), YearName("geng-zi")],
            "ja": [YearName("庚子"), Literal("年"), Month("四月")],
            "zh": [RelatedYear("2020"), YearName("庚子"), Literal("年"), Month("四月")],
            "ar": [RelatedYear("٢٠٢٠"), Literal("("), YearName("geng-zi"), Literal(") "), Month("M04")],
        }
    },

    // Display "year" and "month" fields. (Leap month)
    {
        date: new Date("2020-05-23T00:00:00Z"),
        options: {year: "numeric", month: "long"},
        calendar: "chinese",
        locales: {
            "en": [Month("Fourth Monthbis"), Literal(" "), RelatedYear("2020"), Literal("("), YearName("geng-zi"), Literal(")")],
            "de": [Month("M04bis"), Literal(" "), YearName("geng-zi")],
            "ja": [YearName("庚子"), Literal("年"), Month("閏四月")],
            "zh": [RelatedYear("2020"), YearName("庚子"), Literal("年"), Month("闰四月")],
            "ar": [RelatedYear("٢٠٢٠"), Literal("("), YearName("geng-zi"), Literal(") "), Month("M04bis")],
        }
    },

    // Related year in traditional Korean calendar.
    {
        date: new Date("2019-01-01T00:00:00Z"),
        options: {},
        calendar: "dangi",
        locales: {
            "en": [Month("11"), Literal("/"), Day("26"), Literal("/"), RelatedYear("2018")],
            "ko": [RelatedYear("2018"), Literal(". "), Month("11"), Literal(". "), Day("26"), Literal(".")],
        }
    },

    // Allowing the calendar to modify the pattern selection choice can result in falling back to
    // the root locale patterns in more cases. That can result in displaying the era field by
    // default, among other things.
    {
        date: new Date("2019-01-01T00:00:00Z"),
        options: {},
        calendar: "buddhist",
        locales: {
            "en": [Month("1"), Literal("/"), Day("1"), Literal("/"), Year("2562"), Literal(" "), Era("BE")],
            "th": [Day("1"), Literal("/"), Month("1"), Literal("/"), Year("2562")],
        }
    },
    {
        date: new Date("2019-01-01T00:00:00Z"),
        options: {},
        calendar: "hebrew",
        locales: {
            "en": [Day("24"), Literal(" "), Month("Tevet"), Literal(" "), Year("5779")],
            "he": [Day("24"), Literal(" ב"), Month("טבת"), Literal(" "), Year("5779")],
            "fr": [Day("24"), Literal("/"), Month("04"), Literal("/"), Year("5779"), Literal(" "), Era("A. M.")],
        }
    },
    {
        date: new Date("2019-01-01T00:00:00Z"),
        options: {},
        calendar: "islamic",
        locales: {
            "en": [Month("4"), Literal("/"), Day("25"), Literal("/"), Year("1440"), Literal(" "), Era("AH")],
            "ar": [Day("٢٥"), Literal("\u200F/"), Month("٤"), Literal("\u200F/"), Year("١٤٤٠"), Literal(" "), Era("هـ")],
        }
    },
    {
        date: new Date("2019-01-01T00:00:00Z"),
        options: {},
        calendar: "japanese",
        locales: {
            "en": [Month("1"), Literal("/"), Day("1"), Literal("/"), Year("31"), Literal(" "), Era("H")],
            "ja": [Era("H"), Year("31"), Literal("/"), Month("1"), Literal("/"), Day("1")],
        }
    },
    {
        date: new Date("2019-01-01T00:00:00Z"),
        options: {},
        calendar: "persian",
        locales: {
            "en": [Month("10"), Literal("/"), Day("11"), Literal("/"), Year("1397"), Literal(" "), Era("AP")],
            "fa": [Year("۱۳۹۷"), Literal("/"), Month("۱۰"), Literal("/"), Day("۱۱")],
        }
    },
    {
        date: new Date("2019-01-01T00:00:00Z"),
        options: {},
        calendar: "roc",
        locales: {
            "en": [Month("1"), Literal("/"), Day("1"), Literal("/"), Year("108"), Literal(" "), Era("Minguo")],
            "zh-Hant-TW": [Era("民國"), Year("108"), Literal("/"), Month("1"), Literal("/"), Day("1")],
        }
    },
];

for (let {date, options, calendar, locales} of tests) {
    for (let [locale, result] of Object.entries(locales)) {
        let df = new Intl.DateTimeFormat(`${locale}-u-ca-${calendar}`, {timeZone: "UTC", ...options});
        assertParts(df, date, result);
    }
}

if (typeof reportCompare === "function")
    reportCompare(0, 0, "ok");