Skip to content

Commit 9e53d64

Browse files
committed
Temporal: Split up old Chinese and Dangi calendar tests; remove out-of-normal-range dates
1 parent 18f6ed2 commit 9e53d64

27 files changed

+1968
-793
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2025 Google Inc, Igalia S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-partitiondatetimepattern
6+
description: >
7+
Check that Intl.DateTimeFormat.formatRangeToParts output matches snapshot data
8+
locale: en-US-u-ca-chinese
9+
---*/
10+
11+
const calendar = "chinese";
12+
13+
// verify that Intl.DateTimeFormat.formatRangeToParts output matches snapshot data
14+
function compareFormatRangeToPartsSnapshot(isoString1, isoString2, expectedComponents1, expectedComponents2) {
15+
const date1 = new Date(isoString1);
16+
const date2 = new Date(isoString2);
17+
const formatter = new Intl.DateTimeFormat(`en-US-u-ca-${calendar}`, { timeZone: "UTC" });
18+
const actualComponents = formatter.formatRangeToParts(date1, date2);
19+
20+
function findAll(list, sourceVal, isoString) {
21+
for (let [expectedType, expectedValue] of Object.entries(list)) {
22+
const part = actualComponents.find(({type, source}) => type === expectedType && source == sourceVal);
23+
const contextMessage = `${expectedType} component of ${isoString} formatted in ${calendar}`;
24+
assert.notSameValue(part, undefined, contextMessage);
25+
assert.sameValue(part.value, `${expectedValue}`, contextMessage);
26+
}
27+
}
28+
29+
findAll(expectedComponents1, "startRange", isoString1);
30+
findAll(expectedComponents2, "endRange", isoString2);
31+
}
32+
33+
compareFormatRangeToPartsSnapshot("2000-01-01T00:00Z", "1900-01-01T00:00Z", {
34+
relatedYear: 1999,
35+
month: 11,
36+
day: 25
37+
}, {
38+
relatedYear: 1899,
39+
month: 12,
40+
day: 1
41+
});
42+
43+
compareFormatRangeToPartsSnapshot("1900-01-01T00:00Z", "2100-01-01T00:00Z", {
44+
relatedYear: 1899,
45+
month: 12,
46+
day: 1
47+
}, {
48+
relatedYear: 2099,
49+
month: 11,
50+
day: 21
51+
});
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2025 Google Inc, Igalia S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-partitiondatetimepattern
6+
description: >
7+
Check that Intl.DateTimeFormat.formatRangeToParts output matches snapshot data
8+
locale: en-US-u-ca-dangi
9+
---*/
10+
11+
const calendar = "dangi";
12+
13+
// verify that Intl.DateTimeFormat.formatRangeToParts output matches snapshot data
14+
function compareFormatRangeToPartsSnapshot(isoString1, isoString2, expectedComponents1, expectedComponents2) {
15+
const date1 = new Date(isoString1);
16+
const date2 = new Date(isoString2);
17+
const formatter = new Intl.DateTimeFormat(`en-US-u-ca-${calendar}`, { timeZone: "UTC" });
18+
const actualComponents = formatter.formatRangeToParts(date1, date2);
19+
20+
function findAll(list, sourceVal, isoString) {
21+
for (let [expectedType, expectedValue] of Object.entries(list)) {
22+
const part = actualComponents.find(({type, source}) => type === expectedType && source == sourceVal);
23+
const contextMessage = `${expectedType} component of ${isoString} formatted in ${calendar}`;
24+
assert.notSameValue(part, undefined, contextMessage);
25+
assert.sameValue(part.value, `${expectedValue}`, contextMessage);
26+
}
27+
}
28+
29+
findAll(expectedComponents1, "startRange", isoString1);
30+
findAll(expectedComponents2, "endRange", isoString2);
31+
}
32+
33+
compareFormatRangeToPartsSnapshot("2000-01-01T00:00Z", "1900-01-01T00:00Z", {
34+
relatedYear: 1999,
35+
month: 11,
36+
day: 25
37+
}, {
38+
relatedYear: 1899,
39+
month: 12,
40+
day: 1
41+
});
42+
43+
compareFormatRangeToPartsSnapshot("1900-01-01T00:00Z", "2100-01-01T00:00Z", {
44+
relatedYear: 1899,
45+
month: 12,
46+
day: 1
47+
}, {
48+
relatedYear: 2099,
49+
month: 11,
50+
day: 21
51+
});
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2025 Google Inc, Igalia S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-partitiondatetimepattern
6+
description: >
7+
Check that Intl.DateTimeFormat.formatToParts output matches snapshot data
8+
locale: en-US-u-ca-chinese
9+
---*/
10+
11+
const calendar = "chinese";
12+
13+
// verify that Intl.DateTimeFormat.formatToParts output matches snapshot data
14+
function compareFormatToPartsSnapshot(isoString, expectedComponents) {
15+
const date = new Date(isoString);
16+
const formatter = new Intl.DateTimeFormat(`en-US-u-ca-${calendar}`, { timeZone: "UTC" });
17+
const actualComponents = formatter.formatToParts(date);
18+
for (let [expectedType, expectedValue] of Object.entries(expectedComponents)) {
19+
const part = actualComponents.find(({type}) => type === expectedType);
20+
const contextMessage = `${expectedType} component of ${isoString} formatted in ${calendar}`;
21+
assert.notSameValue(part, undefined, contextMessage);
22+
assert.sameValue(part.value, `${expectedValue}`, contextMessage);
23+
}
24+
}
25+
26+
compareFormatToPartsSnapshot("2000-01-01T00:00Z", {
27+
relatedYear: 1999,
28+
month: 11,
29+
day: 25,
30+
});
31+
32+
compareFormatToPartsSnapshot("1900-01-01T00:00Z", {
33+
relatedYear: 1899,
34+
month: 12,
35+
day: 1,
36+
});
37+
38+
compareFormatToPartsSnapshot("2100-01-01T00:00Z", {
39+
relatedYear: 2099,
40+
month: 11,
41+
day: 21,
42+
});
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2025 Google Inc, Igalia S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-partitiondatetimepattern
6+
description: >
7+
Check that Intl.DateTimeFormat.formatToParts output matches snapshot data
8+
locale: en-US-u-ca-dangi
9+
---*/
10+
11+
const calendar = "dangi";
12+
13+
const dangiYearOffset = new Temporal.PlainDate(1, 1, 1, calendar).year;
14+
15+
// verify that Intl.DateTimeFormat.formatToParts output matches snapshot data
16+
function compareFormatToPartsSnapshot(isoString, expectedComponents) {
17+
const date = new Date(isoString);
18+
const formatter = new Intl.DateTimeFormat(`en-US-u-ca-${calendar}`, { timeZone: "UTC" });
19+
const actualComponents = formatter.formatToParts(date);
20+
for (let [expectedType, expectedValue] of Object.entries(expectedComponents)) {
21+
const part = actualComponents.find(({type}) => type === expectedType);
22+
const contextMessage = `${expectedType} component of ${isoString} formatted in ${calendar}`;
23+
assert.notSameValue(part, undefined, contextMessage);
24+
assert.sameValue(part.value, `${expectedValue}`, contextMessage);
25+
}
26+
}
27+
28+
compareFormatToPartsSnapshot("2000-01-01T00:00Z", {
29+
relatedYear: 1999,
30+
month: 11,
31+
day: 25,
32+
});
33+
34+
compareFormatToPartsSnapshot("1900-01-01T00:00Z", {
35+
relatedYear: 1899,
36+
month: 12,
37+
day: 1,
38+
});
39+
40+
compareFormatToPartsSnapshot("2100-01-01T00:00Z", {
41+
relatedYear: 2099,
42+
month: 11,
43+
day: 21,
44+
});
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// Copyright 2025 Google Inc, Igalia S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.plaindate.from
6+
description: Test `from` with Chinese calendar
7+
features: [Temporal]
8+
---*/
9+
10+
const testChineseData = new Date("2001-02-01T00:00Z").toLocaleString("en-US-u-ca-chinese", {
11+
day: "numeric",
12+
month: "numeric",
13+
year: "numeric",
14+
era: "short",
15+
timeZone: "UTC"
16+
});
17+
const hasOutdatedChineseIcuData = !testChineseData.endsWith("2001");
18+
19+
const calendar = "chinese";
20+
21+
const chineseYearOffset = new Temporal.PlainDate(1, 1, 1, calendar).year;
22+
23+
const cases = {
24+
year2000: {
25+
year: 1999 + chineseYearOffset,
26+
month: 11,
27+
monthCode: "M11",
28+
day: 25
29+
},
30+
year1900: {
31+
year: 1899 + chineseYearOffset,
32+
month: 12,
33+
monthCode: "M12",
34+
day: 1
35+
},
36+
year2100: {
37+
year: 2099 + chineseYearOffset,
38+
month: 12,
39+
monthCode: "M11",
40+
day: 21
41+
}
42+
};
43+
const dates = {
44+
year2000: Temporal.PlainDate.from("2000-01-01"),
45+
year1900: Temporal.PlainDate.from("1900-01-01"),
46+
year2100: Temporal.PlainDate.from("2100-01-01")
47+
};
48+
for (var [name, result] of Object.entries(cases)) {
49+
if (hasOutdatedChineseIcuData) {
50+
continue;
51+
}
52+
const date = dates[name];
53+
const inCal = date.withCalendar(calendar);
54+
55+
assert.sameValue(inCal.era, result.era, `${name}: era`);
56+
assert.sameValue(inCal.eraYear, result.eraYear, `${name}: eraYear`);
57+
assert.sameValue(inCal.year, result.year, `${name}: year`);
58+
assert.sameValue(inCal.month, result.month, `${name}: month`);
59+
assert.sameValue(inCal.monthCode, result.monthCode, `${name}: monthCode`);
60+
assert.sameValue(inCal.day, result.day, `${name}: day`);
61+
62+
const dateRoundtrip2 = Temporal.PlainDate.from({
63+
calendar,
64+
year: result.year,
65+
day: result.day,
66+
monthCode: result.monthCode
67+
});
68+
assert.sameValue(dateRoundtrip2.toString(), inCal.toString());
69+
70+
const dateRoundtrip3 = Temporal.PlainDate.from({
71+
calendar,
72+
year: result.year,
73+
day: result.day,
74+
month: result.month
75+
});
76+
assert.sameValue(dateRoundtrip3.toString(), inCal.toString());
77+
78+
const dateRoundtrip4 = Temporal.PlainDate.from({
79+
calendar,
80+
year: result.year,
81+
day: result.day,
82+
monthCode: result.monthCode
83+
});
84+
assert.sameValue(dateRoundtrip4.toString(), inCal.toString());
85+
86+
assert.throws(RangeError, () => Temporal.PlainDate.from({
87+
calendar,
88+
day: result.day,
89+
month: result.month === 1 ? 2 : result.month - 1,
90+
monthCode: result.monthCode,
91+
year: result.year
92+
}));
93+
}
94+
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// Copyright 2025 Google Inc, Igalia S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.plaindate.from
6+
description: Test `from` with Dangi calendar
7+
features: [Temporal]
8+
---*/
9+
10+
var testChineseData = new Date("2001-02-01T00:00Z").toLocaleString("en-US-u-ca-chinese", {
11+
day: "numeric",
12+
month: "numeric",
13+
year: "numeric",
14+
era: "short",
15+
timeZone: "UTC"
16+
});
17+
var hasOutdatedChineseIcuData = !testChineseData.endsWith("2001");
18+
19+
const calendar = "dangi";
20+
21+
const dangiYearOffset = new Temporal.PlainDate(1, 1, 1, calendar).year;
22+
23+
const cases = {
24+
year2000: {
25+
year: 1999 + dangiYearOffset,
26+
month: 11,
27+
monthCode: "M11",
28+
day: 25
29+
},
30+
year1900: {
31+
year: 1899 + dangiYearOffset,
32+
month: 12,
33+
monthCode: "M12",
34+
day: 1
35+
},
36+
year2100: {
37+
year: 2099 + dangiYearOffset,
38+
month: 12,
39+
monthCode: "M11",
40+
day: 21
41+
}
42+
};
43+
const dates = {
44+
year2000: Temporal.PlainDate.from("2000-01-01"),
45+
year1900: Temporal.PlainDate.from("1900-01-01"),
46+
year2100: Temporal.PlainDate.from("2100-01-01")
47+
};
48+
for (var [name, result] of Object.entries(cases)) {
49+
if (hasOutdatedChineseIcuData) {
50+
continue;
51+
}
52+
const date = dates[name];
53+
const inCal = date.withCalendar(calendar);
54+
55+
assert.sameValue(inCal.era, result.era, `${name}: era`);
56+
assert.sameValue(inCal.eraYear, result.eraYear, `${name}: eraYear`);
57+
assert.sameValue(inCal.year, result.year, `${name}: year`);
58+
assert.sameValue(inCal.month, result.month, `${name}: month`);
59+
assert.sameValue(inCal.monthCode, result.monthCode, `${name}: monthCode`);
60+
assert.sameValue(inCal.day, result.day, `${name}: day`);
61+
62+
const dateRoundtrip2 = Temporal.PlainDate.from({
63+
calendar,
64+
year: result.year,
65+
day: result.day,
66+
monthCode: result.monthCode
67+
});
68+
assert.sameValue(dateRoundtrip2.toString(), inCal.toString());
69+
70+
const dateRoundtrip3 = Temporal.PlainDate.from({
71+
calendar,
72+
year: result.year,
73+
day: result.day,
74+
month: result.month
75+
});
76+
assert.sameValue(dateRoundtrip3.toString(), inCal.toString());
77+
78+
const dateRoundtrip4 = Temporal.PlainDate.from({
79+
calendar,
80+
year: result.year,
81+
day: result.day,
82+
monthCode: result.monthCode
83+
});
84+
assert.sameValue(dateRoundtrip4.toString(), inCal.toString());
85+
86+
assert.throws(RangeError, () => Temporal.PlainDate.from({
87+
calendar,
88+
day: result.day,
89+
month: result.month === 1 ? 2 : result.month - 1,
90+
monthCode: result.monthCode,
91+
year: result.year
92+
}));
93+
}
94+

0 commit comments

Comments
 (0)