Skip to content

Commit b071d6d

Browse files
ptomatoMs2ger
authored andcommitted
Temporal: Ensure year field in PlainMonthDay not used for range check
When constructing PlainMonthDay from a property bag, or applying partial fields to PlainMonthDay, as a special case for the iso8601 calendar, the year field should only be used for applying the overflow parameter, not for range checking. Discovered using snapshot testing. V8/Boa bug: boa-dev/temporal#688
1 parent 454ba1f commit b071d6d

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (C) 2026 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.plainmonthday.from
6+
description: >
7+
As a special case when constructing PlainMonthDay with iso8601 calendar, the
8+
year property is only used for applying the overflow option, not a range check
9+
features: [Temporal]
10+
includes: [temporalHelpers.js]
11+
---*/
12+
13+
var outOfRangeCommonYear = -999999;
14+
var outOfRangeLeapYear = -1000000;
15+
16+
var result = Temporal.PlainMonthDay.from({
17+
year: outOfRangeCommonYear,
18+
month: 1,
19+
day: 1,
20+
});
21+
TemporalHelpers.assertPlainMonthDay(result, "M01", 1, "ISO year is not checked for range");
22+
23+
var commonResult = Temporal.PlainMonthDay.from({
24+
year: outOfRangeCommonYear,
25+
monthCode: "M02",
26+
day: 29
27+
});
28+
TemporalHelpers.assertPlainMonthDay(commonResult, "M02", 28, "ISO year is used to apply overflow");
29+
30+
assert.throws(RangeError, function () {
31+
Temporal.PlainMonthDay.from({
32+
year: outOfRangeCommonYear,
33+
monthCode: "M02",
34+
day: 29
35+
}, { overflow: "reject" });
36+
}, "ISO year is used to apply overflow");
37+
38+
var leapResult = Temporal.PlainMonthDay.from({
39+
year: outOfRangeLeapYear,
40+
monthCode: "M02",
41+
day: 29
42+
});
43+
TemporalHelpers.assertPlainMonthDay(leapResult, "M02", 29, "ISO year is used to apply overflow");
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (C) 2026 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.plainmonthday.prototype.with
6+
description: >
7+
As a special case applying partial fields to PlainMonthDay with iso8601
8+
calendar, the year property is only used for applying the overflow option, not
9+
a range check
10+
features: [Temporal]
11+
includes: [temporalHelpers.js]
12+
---*/
13+
14+
var outOfRangeCommonYear = -999999;
15+
var outOfRangeLeapYear = -1000000;
16+
17+
var md = new Temporal.PlainMonthDay(1, 1, "iso8601", 1972);
18+
var result = md.with({ year: outOfRangeCommonYear });
19+
TemporalHelpers.assertPlainMonthDay(result, "M01", 1, "ISO year is not checked for range");
20+
21+
var leap = new Temporal.PlainMonthDay(2, 29, "iso8601", 1972);
22+
var commonResult = leap.with({ year: outOfRangeCommonYear });
23+
TemporalHelpers.assertPlainMonthDay(commonResult, "M02", 28, "ISO year is used to apply overflow");
24+
25+
assert.throws(RangeError, function () {
26+
leap.with({ year: outOfRangeCommonYear }, { overflow: "reject" });
27+
}, "ISO year is used to apply overflow");
28+
29+
var leapResult = leap.with({ year: outOfRangeLeapYear });
30+
TemporalHelpers.assertPlainMonthDay(leapResult, "M02", 29, "ISO year is used to apply overflow");

0 commit comments

Comments
 (0)