Skip to content

Commit 10f5b2f

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

28 files changed

+2059
-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: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
includes: [temporalHelpers.js]
8+
features: [Temporal]
9+
---*/
10+
11+
const testChineseData = new Date("2001-02-01T00:00Z").toLocaleString("en-US-u-ca-chinese", {
12+
day: "numeric",
13+
month: "numeric",
14+
year: "numeric",
15+
era: "short",
16+
timeZone: "UTC"
17+
});
18+
const hasOutdatedChineseIcuData = !testChineseData.endsWith("2001");
19+
20+
const calendar = "chinese";
21+
22+
const chineseYearOffset = new Temporal.PlainDate(1, 1, 1, calendar).year;
23+
24+
const cases = {
25+
year2000: {
26+
year: 1999 + chineseYearOffset,
27+
month: 11,
28+
monthCode: "M11",
29+
day: 25
30+
},
31+
year1900: {
32+
year: 1899 + chineseYearOffset,
33+
month: 12,
34+
monthCode: "M12",
35+
day: 1
36+
},
37+
year2100: {
38+
year: 2099 + chineseYearOffset,
39+
month: 12,
40+
monthCode: "M11",
41+
day: 21
42+
}
43+
};
44+
const dates = {
45+
year2000: Temporal.PlainDate.from("2000-01-01"),
46+
year1900: Temporal.PlainDate.from("1900-01-01"),
47+
year2100: Temporal.PlainDate.from("2100-01-01")
48+
};
49+
for (var [name, result] of Object.entries(cases)) {
50+
if (hasOutdatedChineseIcuData) {
51+
continue;
52+
}
53+
const date = dates[name];
54+
const inCal = date.withCalendar(calendar);
55+
56+
assert.sameValue(inCal.era, result.era, `${name}: era`);
57+
assert.sameValue(inCal.eraYear, result.eraYear, `${name}: eraYear`);
58+
assert.sameValue(inCal.year, result.year, `${name}: year`);
59+
assert.sameValue(inCal.month, result.month, `${name}: month`);
60+
assert.sameValue(inCal.monthCode, result.monthCode, `${name}: monthCode`);
61+
assert.sameValue(inCal.day, result.day, `${name}: day`);
62+
63+
const dateRoundtrip2 = Temporal.PlainDate.from({
64+
calendar,
65+
year: result.year,
66+
day: result.day,
67+
monthCode: result.monthCode
68+
});
69+
assert.sameValue(dateRoundtrip2.toString(), inCal.toString());
70+
71+
const dateRoundtrip3 = Temporal.PlainDate.from({
72+
calendar,
73+
year: result.year,
74+
day: result.day,
75+
month: result.month
76+
});
77+
assert.sameValue(dateRoundtrip3.toString(), inCal.toString());
78+
79+
const dateRoundtrip4 = Temporal.PlainDate.from({
80+
calendar,
81+
year: result.year,
82+
day: result.day,
83+
monthCode: result.monthCode
84+
});
85+
assert.sameValue(dateRoundtrip4.toString(), inCal.toString());
86+
87+
assert.throws(RangeError, () => Temporal.PlainDate.from({
88+
calendar,
89+
day: result.day,
90+
month: result.month === 1 ? 2 : result.month - 1,
91+
monthCode: result.monthCode,
92+
year: result.year
93+
}));
94+
}
95+
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
includes: [temporalHelpers.js]
8+
features: [Temporal]
9+
---*/
10+
11+
var testChineseData = new Date("2001-02-01T00:00Z").toLocaleString("en-US-u-ca-chinese", {
12+
day: "numeric",
13+
month: "numeric",
14+
year: "numeric",
15+
era: "short",
16+
timeZone: "UTC"
17+
});
18+
var hasOutdatedChineseIcuData = !testChineseData.endsWith("2001");
19+
20+
const calendar = "dangi";
21+
22+
const dangiYearOffset = new Temporal.PlainDate(1, 1, 1, calendar).year;
23+
24+
const cases = {
25+
year2000: {
26+
year: 1999 + dangiYearOffset,
27+
month: 11,
28+
monthCode: "M11",
29+
day: 25
30+
},
31+
year1900: {
32+
year: 1899 + dangiYearOffset,
33+
month: 12,
34+
monthCode: "M12",
35+
day: 1
36+
},
37+
year2100: {
38+
year: 2099 + dangiYearOffset,
39+
month: 12,
40+
monthCode: "M11",
41+
day: 21
42+
}
43+
};
44+
const dates = {
45+
year2000: Temporal.PlainDate.from("2000-01-01"),
46+
year1900: Temporal.PlainDate.from("1900-01-01"),
47+
year2100: Temporal.PlainDate.from("2100-01-01")
48+
};
49+
for (var [name, result] of Object.entries(cases)) {
50+
if (hasOutdatedChineseIcuData) {
51+
continue;
52+
}
53+
const date = dates[name];
54+
const inCal = date.withCalendar(calendar);
55+
56+
assert.sameValue(inCal.era, result.era, `${name}: era`);
57+
assert.sameValue(inCal.eraYear, result.eraYear, `${name}: eraYear`);
58+
assert.sameValue(inCal.year, result.year, `${name}: year`);
59+
assert.sameValue(inCal.month, result.month, `${name}: month`);
60+
assert.sameValue(inCal.monthCode, result.monthCode, `${name}: monthCode`);
61+
assert.sameValue(inCal.day, result.day, `${name}: day`);
62+
63+
const dateRoundtrip2 = Temporal.PlainDate.from({
64+
calendar,
65+
year: result.year,
66+
day: result.day,
67+
monthCode: result.monthCode
68+
});
69+
assert.sameValue(dateRoundtrip2.toString(), inCal.toString());
70+
71+
const dateRoundtrip3 = Temporal.PlainDate.from({
72+
calendar,
73+
year: result.year,
74+
day: result.day,
75+
month: result.month
76+
});
77+
assert.sameValue(dateRoundtrip3.toString(), inCal.toString());
78+
79+
const dateRoundtrip4 = Temporal.PlainDate.from({
80+
calendar,
81+
year: result.year,
82+
day: result.day,
83+
monthCode: result.monthCode
84+
});
85+
assert.sameValue(dateRoundtrip4.toString(), inCal.toString());
86+
87+
assert.throws(RangeError, () => Temporal.PlainDate.from({
88+
calendar,
89+
day: result.day,
90+
month: result.month === 1 ? 2 : result.month - 1,
91+
monthCode: result.monthCode,
92+
year: result.year
93+
}));
94+
}
95+

0 commit comments

Comments
 (0)